40
Size of the stack and heap limited by the OS
Memory-allocation
Stack-memory
Heap-memory
Virtual-memory
Operating Systems

If you are reading about Memory Layout first time then I'll strongly recommend you to read Memory Layout of C Program . It contents information like when we run any C-program, its executable image is loaded into RAM of computer in an organized manner. But all curious minds needs to get the question: What is maximum limit of heap or stack in PCB that get created by OS for any program?

I was also interested to know what is maximum limit of LinkedList or other similar data types that gets created on heap.After studying about it, I got to know heap can grow till maximum virtual memory provided by OS.

So explaining about this sentence, There are two different memory limits namely virtual memory limit and the physical memory limit. I'll only demonstrate about virtual memory cause its related to this topic.

Virtual memory get available to PCB for allocating space at run time. While heap can grow to all available memory, mostly stack can't be grows whenever required. This is because stack mostly gets involved into multi-threaded programming and if systems allows stack to grow whenever required then it will be difficult to track each thread at real time cause multi-threaded programs need separate stack for each thread. For Heap memory, when heap memory gets full in PCB then it uses virtual memory to run the programs. Now next curiosity can be, what is maximum limit of Virtual Memory?

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. There is a special version of Linux that does not reserve anything giving you full 4GiB. And if you are using 64-bit windows platform, then it is 16 terabytes.

So basically you can allocate memory at run time till this huge virtually memory gets full.

Author

Notifications

?