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

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


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.


The restriction depends on the operating system. Standard Linux is 2 Gb, Solaris is 3 Gb, Windows is (I'm told) 2 or 3 depending on how PAE is used.

However, you don't get all of that 2G for your data. Your code will take some of it, and your program's stack will take some, and the C library will take some, as will any other shared libraries that you reference. Typically the OS will organize the code, heap, and stack such that there are intentional gaps between them.

As for your final question: it's all virtual memory. What you are actually asking is "if the programs in my machine use all that physical memory, will the OS use swap." And the answer is yes, but not quite the way you think.

A CPU can only access physical RAM. It knows nothing of data stored on disk. So to give physical memory to a running process, the OS will take that memory from another process. In order to take the memory, it will write it to swap. When that other process needs to access the memory, the OS will read it back in, potentially writing some other process' memory to swap.


Typically, a 32-bit OS can only address 4GB of physical RAM. In practice this limit tends to be somewhat lower, but can be alleviated with the use of virtual RAM. On certain versions of Windows it can be increased through the use of Physical Address Extension.

More importantly to your question, on 32-bit Windows there is also a 2GB limit on the address space available to a user application. This places a hard constraint on the amount of memory that a single application can use, irrespective of the amount of physical or virtual RAM available. The default 2GB limit can be increased to 3GB.

The following page explains the limits in detail: http://msdn.microsoft.com/en-us/library/aa366778(v=vs.85).aspx