LARA

Memory Layout for Compiled Program

Operating System
User Process Code
Machine Code
User Process Data
MaxBlock
Stack
:
\:/
/:\
:
Dynamically Allocated Heap
Global Static Data (Const,Var)
0

Both dynamically allocated heap and stack expand

  • heap need not be contiguous can request more memory from the OS if needed
  • stack grows downwards

Heap is more general:

  • can allocate, read/write, and deallocate in any order
  • Garbage Collector does deallocation automatically

Stack is more efficient - allocation simple increment, decrement

Top of stack pointer (SP) is often a register

If stack grows towards smaller addresses:

  • to allocate N bytes (push)

SP := SP - N

  • to deallocate N bytes (pop)

SP := SP + N