Question

What is the amount of heap and stack available to a Program and how do I determine it? And is it dependent on the compiler or PC or both?

Was it helpful?

Solution

It's "unlimited" :]. Every process receives a virtual address space which is only limited by CPU and OS implementation. If a CPU or OS is 32 bit, then the process gets a possibility to address ~4GB of virtual memory (even if you have less RAM installed in your PC). On a 64 bit CPU and 64 bit os, current implementations limit the virtual address space to 48 bit, so a process believes that it can use up to 256TB of memory.

The OS will dynamically try to reserve as much heap and stack space as the process needs.

OTHER TIPS

It's dependent on the OS, the hardware and other running programs. You can ask the OS about the amount of physical memory and swap space, but not about how much heap and stack is actually available to your program. Your program get its own virtual memory space, but whether the OS can back all the allocations in that space can only be known if you try to allocate it -- if there's no memory to back it, the allocation will fail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top