2

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 ?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
devMiyax
  • 65
  • 1
  • 8

2 Answers2

5

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.

Mike Kwan
  • 24,123
  • 12
  • 63
  • 96
  • 1
    Your link is Windows CE. I don't believe it's true for Windows in general. See http://msdn.microsoft.com/en-us/library/windows/desktop/aa366887(v=vs.85).aspx – Mark Ransom Apr 13 '12 at 22:57
  • I seem to recall above 0x70000000 being reserved for the kernel on Windows but couldn't find a reference for this – Mike Kwan Apr 13 '12 at 23:44
0

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.

Branko Dimitrijevic
  • 50,809
  • 10
  • 93
  • 167