c++ - VirtualAlloc failing -
i trying use virtualalloc reserve , commit block of memory , again extend block. unfortunately, returning null error error_invalid_address despite virtualquery saying address range requested free. here's code:
void* allocation = virtualalloc(null, 4096, mem_reserve | mem_commit, page_readwrite); void* desirednextallocation = (char*)allocation + 4096; memory_basic_information info; size_t memory_info = virtualquery(desirednextallocation, &info, sizeof(info)); void* extended = virtualalloc(desirednextallocation, 4096, mem_reserve | mem_commit, page_readwrite);
the first allocation returns 0x00000000000d0000. call virtualquery results in following data in 'info':
baseaddress 0x00000000000d1000 void * allocationbase 0x0000000000000000 void * allocationprotect 0x00000000 unsigned long regionsize 0x00000000000ff000 unsigned __int64 state 0x00010000 unsigned long protect 0x00000001 unsigned long type 0x00000000 unsigned long
i interpret mean there 0xff available pages beginning @ 0xd1000 in mem_free state. why attempt commit page @ 0xd1000 fail?
i'm running windows 7 , 64 bit build.
i have read several stackoverflow posts virtualalloc seem imply code should work understanding of documentation.
from documentation virtualalloc:
if memory being reserved, specified address rounded down nearest multiple of allocation granularity.
in case, address 0xd1000 rounded down address 0xd0000, reserved , hence invalid.
Comments
Post a Comment