Jack Kada Jack Kada - 2 months ago 6x
C++ Question

What is the maximum memory available to a C++ application on 32-bit Windows?

Just wondering if there is a restriction on the max memory that a C++ application uses

I understand that this is 2GB - Is that correct?

If a C++ app tries to request more then 2GB memory does this cause a memory crash?

Final question - If the machine the C++ app is running on is already low on memory and a C++ app asks for 100MB of array (ie contiguous memory) will the OS accommodate this by using virtual memory?


It will cause a dynamic memory allocation failure, which usually will make the resultant application crash, but technically, an application could be written to withstand this event. 2GB is indeed the user address space size for an individual process- an application may use multiple processes (easiest example: Chrome). If an application asks for 100MB of contiguous memory, that memory must be virtually contiguous even if not physically contiguous, and if there aren't enough contiguous pages available then it's a failed allocation.

Virtual memory is always used- all memory is virtual.

2GB is the limit under most circumstances. What happens is that normally, 2GB is for the user and 2GB for the kernel, but you can ask Windows to make this 3GB for the user and 1GB for the kernel (at some risk), and on 64bit, the whole 4GB of 32bit address space is available to the user. The increased address space is only available if you compile your application as /LARGEADDRESSAWARE.