Module 12: Dynamic Memory Allocation (Heap Management)

Duration: 4.0 Hours • Advanced Memory
1. Stack vs Heap 1 / 4

Stack Memory vs Heap Memory Dynamics

Automatic scoped allocation vs Manual runtime management

FeatureStack MemoryHeap Memory
ManagementAutomatic by CPU / CompilerManual by Programmer (malloc / free)
Allocation SpeedUltra-fast (Single CPU instruction pointer decrement)Moderate (Searches free memory chunk lists)
Capacity LimitSmall (e.g. 8 MB per thread on macOS/Linux)Large (Limited only by physical RAM + Swap)
LifetimeDestroyed when function exitsPersists until explicitly free()d or process exits