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

2
  • 1
    AFAIK, there's no way to reserve memory as VirtualAlloc does. For contiguous allocation use mmap. Commented Aug 24, 2010 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) Commented Aug 25, 2010 at 7:23

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.