4

What's the equivalent to Windows's VirtualAlloc in OS X? That is, how can i reserve a contiguous address space without actually commiting it and then commit chunks of it later?

Thanks,

Alex

Alex
  • 2,000
  • 2
  • 17
  • 29
  • 1
    AFAIK, there's no way to reserve memory as `VirtualAlloc` does. For contiguous allocation use `mmap`. – jweyrich Aug 24 '10 at 21:15
  • 1
    I have also seen `mmap` used for contiguous allocation on OS X and other Unices. Could a specialist point out the differences, if any, with Windows' `VirtualAlloc`? Perhaps someone who has answered that they weren't the same? (Note: the users of `mmap` I was referring to went back to `malloc` but I can't remember the reason) – Pascal Cuoq Aug 25 '10 at 07:23

2 Answers2

9

The mmap() function, called with MAP_ANON | MAP_PRIVATE, is very roughly equivalent to VirtualAlloc() with the MEM_RESERVE flag. Memory is then committed by touching each page in the mapping.

caf
  • 225,337
  • 36
  • 308
  • 455
0

No, unfortunately, there is no exact equivalent to VirtualAlloc.

Pablo Santa Cruz
  • 170,119
  • 31
  • 233
  • 283