Stack Memory vs Heap Memory Dynamics
Automatic scoped allocation vs Manual runtime management
| Feature | Stack Memory | Heap Memory |
|---|---|---|
| Management | Automatic by CPU / Compiler | Manual by Programmer (malloc / free) |
| Allocation Speed | Ultra-fast (Single CPU instruction pointer decrement) | Moderate (Searches free memory chunk lists) |
| Capacity Limit | Small (e.g. 8 MB per thread on macOS/Linux) | Large (Limited only by physical RAM + Swap) |
| Lifetime | Destroyed when function exits | Persists until explicitly free()d or process exits |