Recent

Author Topic: Allocate memory pages  (Read 2587 times)

LemonParty

  • Sr. Member
  • ****
  • Posts: 373
Allocate memory pages
« on: February 27, 2025, 03:46:39 pm »
In Windows we have VirtualAlloc function for allocate memory pages. What is used in UNIX?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

Khrys

  • Sr. Member
  • ****
  • Posts: 348
Re: Allocate memory pages
« Reply #1 on: February 27, 2025, 03:50:55 pm »
mmap,  and  mprotect  is analogous to  VirtualProtect

LemonParty

  • Sr. Member
  • ****
  • Posts: 373
Re: Allocate memory pages
« Reply #2 on: February 27, 2025, 04:14:43 pm »
So if I want just memory I have to pass 0 to fd and offset arguments of mmap?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

MarkMLl

  • Hero Member
  • *****
  • Posts: 8505
Re: Allocate memory pages
« Reply #3 on: February 27, 2025, 05:04:19 pm »
So if I want just memory I have to pass 0 to fd and offset arguments of mmap?

There's an example at https://www.freepascal.org/docs-html/current/rtl/baseunix/fpmmap.html which suggests that it's not that simple. I've not used it ** , and suggest that you look for online examples- even if (shock! Horror!!) they're written in C etc.

** I've not used it in Pascal. I've used it in some C-based video stuff, but was doing so by rote based on existing code and there is absolutely no way I'd set myself up as an expert. I believe it's covered by POSIX, so examples should be fairly portable.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

LemonParty

  • Sr. Member
  • ****
  • Posts: 373
Re: Allocate memory pages
« Reply #4 on: February 27, 2025, 05:52:38 pm »
Seems work.
Code: Pascal  [Select][+][-]
  1. Fpmmap(nil, Size, PROT_EXEC or PROT_READ or PROT_WRITE, MAP_SHARED or MAP_ANONYMOUS, -1, 0)
MAP_ANONYMOUS should be specified if no need to map to a file.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

 

TinyPortal © 2005-2018