What is the "standard" stack size and heap in a C program?

I read that the size of the “standard” and start stack in Linux is ~ 8 MB, and Windows is 1 MB.

But how does heap distribution work? Does the OS indicate a "virtual" size on the heap of the process, as does the stack with fixed and reserved memory?

+6
source share
2 answers

In the classic version, the program layout has a “text” (or “code”) segment at the lower end of the memory, followed by fixed data (“data” and “bss” segments), followed by a space, with the stack growing down from high memory . The gap in the middle becomes a heap that grows from the end of the data to the stack.

Everything is more complicated with streaming programs loaded with shared libraries, shared memory, etc.

The size of the initial stack depends on o / s. The initial heap size is logically zero, but tends to grow almost immediately (as the program and shared libraries load).

+3
source

There is no general "standard size". Individual operating systems will have a default size, but usually they can be changed using the appropriate parameters in the program image or on the command line.

C runs on a wide range of systems from tiny microprocessors, with only a few hundred bytes of available memory, to giant processor arrays with hundreds of gigabytes.

On your large systems (including most Windows and Linux environments), the stack and heap will be assigned to segments that can be extended, so physical memory for maximum sizes should not be pre-reserved. Many microphones, however, do not have memory matching equipment, and sizes must be reserved beforehand (although sometimes the stack and heap are forced to grow together, so there is only one common limit).

+2
source

Source: https://habr.com/ru/post/900830/


All Articles