Memory Layout

The layout of a program in memory is as follows:

  1. Stack — Temporary, local scope data (params, local variables).
  2. Heap — Dynamically allocated memory (e.g. Malloc).
  3. Data — Global variables
  4. Text — Executable code

There is sufficient space between the Stack and Heap sections to allow them to expand.