O'Reilly logo

Windows® via C/C++, Fifth Edition by Christophe Nasarre, Jeffrey Richter

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reserving a Region and Committing Storage Simultaneously

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required