I have two memory regions I'm allocating with VirtualAlloc
: 0x1E0000 (Size: 0x39000, Reserve)
and 0x219000 (Size: 0x3000, Commit)
. These are both within the same allocation boundary (which in this case is rounded to 0x40000 (64K*4)
), and the second region starts where the first ends.
Now forget the commit part for a minute. If I MEM_RESERVE
the first 0x39000
and then MEM_RESERVE
the next 0x3000
, I get ERROR_INVALID_ADDRESS
. However, if I MEM_RESERVE
both in one go, 0x39000+0x3000=0x3C000
, then it works, and I can use MEM_COMMIT
to commit the second region successfully.
Why is that? Why can't I reserve each part on its own instead of as one big reserved region? After reserving the first region the remaining area within the allocation (0x219000-0x21FFFF)
will have the MEM_FREE
state, so how come I cannot reserve the first 0x3000
of the remaining 0x7000
in the allocation boundary?
Copyright Notice:Content Author:「Mikubyte」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40901127/why-cant-i-reserve-two-contiguous-memory-regions-in-the-same-allocation-without