Question

I worte the code below

 void * ptr1 = VirtualAlloc((void*)0x70000000, 32*1024*1024, MEM_RESERVE, PAGE_READWRITE);
 void * ptr2 = VirtualAlloc((void*)0x80000000, 4*1024*1024, MEM_RESERVE, PAGE_READWRITE);

But VirtualAlloc fails and the value of ptr1,ptr2 are always NULL. I want to use the adress 0x70000000,0x80000000. Does anyone know how I can use these adress ?

Was it helpful?

Solution

This part of the memory is not accessible for usermode applications. From the following MSDN page:

User applications cannot call VirtualAlloc with shared heap address range (0x70000000 to 0x7fffffff) because this is read-only for user applications and read/write for kernel mode.

OTHER TIPS

Are you sure some of the pages in the requested memory block are not already reserved (or committed)? VirtualAlloc cannot reserve a reserved page.

Why are 0x70000000 and 0x80000000 special? In the flat memory model, there is no reason why one address would be preferable to any other.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top