If I call
VirtualAlloc, 1001000h, 1000, MEM_RESERVE, PAGE_READWRITE
and the call succeeds, the base will be 1000000h and the size of the region will be 2000h, because when reserving memory the address will be rounded down to the next 64 kB boundary. But if I want to let this region grow afterwards so its size is, say, 8000h (1000000h-1007FFFh), how could this be done. There is no VirtualRealloc and all my tries:
- VirtualAlloc(1002000h, 6000h, MEM_RESERVE)
- VirtualAlloc(1000000h, 8000h, MEM_RESERVE)
- VirtualAlloc(1002000h, 6000h, MEM_COMMIT)
failed :mad:
VirtualAlloc is not the suited API to do that, use Heap APIs.
But beware, with HeapReAlloc, base address may be changed unless you specifiy HEAP_REALLOC_IN_PLACE_ONLY flag.
But beware, with HeapReAlloc, base address may be changed unless you specifiy HEAP_REALLOC_IN_PLACE_ONLY flag.
the above tries were done in XP.
On Win9x, this seems to be no issue, because there the size of the region returned seems to have been rounded up to a 64 kB boundary (1000000h-100FFFFh), and thus a following call of VirtualAlloc(1002000h, 6000h, MEM_COMMIT) doesn't fail!
On Win9x, this seems to be no issue, because there the size of the region returned seems to have been rounded up to a 64 kB boundary (1000000h-100FFFFh), and thus a following call of VirtualAlloc(1002000h, 6000h, MEM_COMMIT) doesn't fail!
> VirtualAlloc is not the suited API to do that, use Heap APIs.
> But beware, with HeapReAlloc, base address may be changed unless you specifiy HEAP_REALLOC_IN_PLACE_ONLY flag.
Thanks, I am aware of HeapRealloc(), but the heap functions are totally different animals.
> But beware, with HeapReAlloc, base address may be changed unless you specifiy HEAP_REALLOC_IN_PLACE_ONLY flag.
Thanks, I am aware of HeapRealloc(), but the heap functions are totally different animals.
The difference between RESERVE and COMMIT is that COMMIT enables the memory space for use. That includes enabling the page swapping of the memory space, if it's swappable.
If you want to grow in-place, then you want to reserve the maximum space you'll ever need, and commit only what you currently need.
If you want to grow in-place, then you want to reserve the maximum space you'll ever need, and commit only what you currently need.