Run-Time Environment
1. What It Is
The run-time environment manages memory layout + execution state while the target program runs: where globals, stack frames, heap live, and how calls access them.
2. Memory Divisions
high → [stack (frames, grows down)] [gap] [heap (malloc, grows up)] [static/global] [code]
| Area | Holds | Lifetime |
|---|---|---|
| Code | instructions | whole run |
| Static | globals, static vars | whole run |
| Heap | malloc/new objects |
explicit free/GC |
| Stack | activation records (locals, params, return addr) | call duration |
3. Activation Record (Frame)
| return value | params | control link (caller fp) | access link (nonlocal scope) | return address | locals | temps |
Control link → caller frame; access link → lexically enclosing scope (for nested functions/pascal).
4. Static vs Stack vs Heap Allocation
- Static: fixed addresses (globals, FORTRAN) — no recursion.
- Stack: push frame on call, pop on return — supports recursion.
- Heap: dynamic lifetime (objects, closures) — needs GC/manual free.
5. Exam Points
- Draw memory layout + frame fields — 7 marks, very frequent.
- Static vs stack vs heap comparison — 5 marks, frequent.
- Control vs access link roles — 3 marks, frequent.