Process Memory Layout¶
A simple view looks like this (from top to bottom):
-
Kernel Space (not directly accessible)
-
Stack: At the top, you have the stack, which grows downwards↓.
- Heap: A region called the heap, used for dynamically allocated memory like
malloc. - .bss / .data: Here we have global variables and static data.
- .text: At the bottom, you have the program’s code section, where the machine instructions live.
We care most about the stack.
Whenever a function is called, some important things are placed on the stack:
- The return address – this is the address of the instruction where the program should continue after the function finishes.
- The saved base pointer (the saved
RBP), which helps the function keep track of its local variables. - The local variables themselves, like small arrays or integers.