What are the consequences of reserving a huge amount of memory, most of which is never committed?

Raymond Chen

A customer had an idea of solving a program by reserving a huge amount of memory with Virtual­Alloc, and then committing only the parts that are actually needed. And by huge, they’re talking about 100GB. (Obviously, on a 64-bit machine.) Is this okay, or is it a bad idea, or is it a terrible idea?

Starting in Windows 8.1 and Windows Server 2012 R2, it’s cheap to reserve a lot of virtual address space. No major memory allocation or other charges occur until you start committing pages, in which case the memory requirements are proportional to the amount of address space you commit, rather than the amount of address space you reserve.

Things were different in earlier versions of Windows. Back then, reserving address space still incurs a cost for creating the page tables required to map the reserved region. In the above example, a 100GB reservation would cost 200MB of memory for the page tables. Depending on the nature of the system you intend to run the program on, this may be an acceptable cost.


Discussion is closed.

Feedback usabilla icon