Search code examples
c++cwinapivirtualalloc

VirtualAlloc address


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 ?


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.