On this page
  1. Call Stack & Heap
  2. Contents
  3. Process Virtual Memory Layout
  4. Stack vs. Heap Trade-Offs

Call Stack & Heap

Prev: Compilation, Interpretation & JIT | Up: memory_and_execution | Next: Pointers, References & Indirection
Rel: Pointers, References & Indirection, Memory Management Models
Ref: Wikipedia — Call Stack
Tags: #public #prog #programming #memory #stack #heap


Contents


Process Virtual Memory Layout

High addresses
  ┌─────────────────────────┐
  │ Call Stack (grows down) │  <- Function frames, local fixed-size values
  │           ↓             │
  │      (free space)       │
  │           ↑             │
  │ Heap (grows up)         │  <- Dynamically sized / long-lived allocations
  ├─────────────────────────┤
  │ Static / Global Data    │  <- Global & static variables (.data / .bss)
  ├─────────────────────────┤
  │ Text / Code Segment     │  <- Read-only executable machine instructions
  └─────────────────────────┘
Low addresses

Stack vs. Heap Trade-Offs

Property Call Stack Heap
Allocation speed Single pointer bump ($O(1)$, nanoseconds) Allocator search + metadata bookkeeping
Lifetime Strictly tied to function return (LIFO) Arbitrary; outlives creating function
Size Small fixed limit (typically 1–8 MiB/thread) Bounded by system virtual memory
CPU Cache Excellent spatial locality Prone to fragmentation & cache misses

Linked from

Related notes