I have read that the "standard" and initial stack size on Linux is ~8MB and Windows is ~1MB.
But how does the heap allocation work? Does the OS set a "virtual" size to the process heap like it does for the stack with committed and reserved memory?
Classically, the layout of a program has the 'text' (or 'code') segment at the low end of memory, followed by the fixed data ('data' and 'bss' segments), followed by a gap, with the stack growing downwards from high memory. The gap in the middle becomes the heap, which grows from the end of the data towards the stack.
Things are more complex with threaded programs, shared libraries loaded, shared memory, etc.
The initial stack size is o/s dependent. The initial heap size is logically zero, but tends to grow almost immediately (as the program and the shared libraries are loaded).
There is no general "standard size". Individual operating systems will have a default size, but usually they can be altered with appropriate parameters in the program image or on the command line.
C executes in a vast range of systems from tiny microprocessors with only a few hundred bytes of available memory to gigantic processor arrays with hundreds of gigabytes.
In your larger systems (including most Windows and Linux environments) the stack and heap will be assigned to segments that can be expanded, so that physical memory for maximum sizes does not need to be pre-reserved. Many micros, though, lack memory mapping hardware and the sizes must be pre-reserved (though sometimes the stack and heap are made to grow towards each other so that there's only one common limit).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With