

When you ask the system to allocate memory, it gives some to you, but only allocates the virtual memory.

On Linux what happens when you run out of physical memory depends on the vm.overcommit_memory system setting. How much physical memory a process is using is very fuzzy number, because some memory is shared between processes (the code, shared libraries and any other mapped files), data from files are loaded into memory on demand and discarded when there is memory shortage and "anonymous" memory (the one not backed by files) may be swapped. Physical memory is usually only allocated by the operating system when the process needs to access it. On 64-bit platforms the virtual memory is 64EiB and you don't have to think about it. It is useful for the rare case of large databases where the last 1GiB saves the day, but for regular use it is slightly slower due to the additional page table reloads. There is a special version of Linux that does not reserve anything giving you full 4GiB. On 32-bit platforms the total amount of virtual memory is 4GiB, both Linux and Windows normally reserving last 1GiB for kernel, giving you at most 3GiB of address space. One reason why stack can't be auto-grown (arbitrarily) is that multi-threaded programs need separate stack for each thread, so they would eventually get in each other's way. The virtual memory also contains any memory-mapped files and hardware. IIRC default limit for stack is 8MiB on Linux and 1MiB on Windows and can be changed on both systems. While heap can grow to all available memory, most systems don't auto-grow stacks. The free virtual memory is not initially marked as usable, but is marked such during allocation.

That gives heap and stack free space to grow, the other areas being known at process startup and fixed.

Usually at the very beginning is the executable code and static data and past that grows the heap, while at the end is area reserved by kernel, before it the shared libraries and stack (which on most platforms grows down). The virtual memory is limited by size and layout of address space available. The virtual memory limit and the physical memory limit.
