At times, you’ll want to reserve a region and commit storage to it simultaneously. You can do this by placing a single call to
VirtualAlloc as follows:
PVOID pvMem = VirtualAlloc(NULL, 99 * 1024, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
This call is a request to reserve a 99-KB region and commit 99 KB of physical storage to the region. When the system processes this call, it first searches your process’ address space to find a contiguous area of unreserved address space large enough to hold 100 KB in 25 pages (on a 4-KB page machine) or 104 KB in 13 pages (on an 8-KB page machine).
The system searches the address space because I specified
NULL as the
pvAddress parameter. If I had specified ...