This topic belongs to the Runtime Environment / Code Generation phase of a compiler. It explains how memory is organized when a program runs and how space is allocated for functions, variables, and procedures.
Storage organization refers to how memory is arranged and managed during program execution.
👉 It divides memory into different regions to store:
A typical program memory is divided into 4 main sections:
+----------------------+
| Text Segment | ← Program code (instructions)
+----------------------+
| Static / Data Area | ← Global & static variables
+----------------------+
| Heap | ← Dynamic memory (malloc/new)
+----------------------+
| Stack | ← Function calls, local variables
+----------------------+
Example:
malloc(), new
Stack allocation is a method of allocating memory for function calls in a Last In First Out (LIFO) manner using a stack.
👉 Each function call gets a block called:
Activation Record (Stack Frame)
An activation record is a block of memory used to store information about a function call.
+----------------------+
| Parameters |
+----------------------+
| Return Address |
+----------------------+
| Control Link |
+----------------------+
| Access Link |
+----------------------+
| Local Variables |
+----------------------+
| Temporary Values |
+----------------------+
Memory block (activation record) is created
New frame is pushed
Function executes using its frame
Frame is popped from stack
| Function C |
| Function B |
| Function A | ← top of stack
When C finishes:
| Function B |
| Function A |
int main() {
int x = 10;
fun();
}
void fun() {
int y = 20;
}
main() activation record createdfun() called → new activation record pushedfun() completes → poppedmain()✔ Fast allocation and deallocation ✔ Follows LIFO order ✔ Memory reused automatically ✔ Used for function calls ✔ Efficient for recursive programs
❌ Cannot handle dynamic data (fully flexible structures) ❌ Limited lifetime of variables ❌ Not suitable for objects needing long-term storage
👉 That’s why heap is also used.
| Feature | Stack | Heap |
|---|---|---|
| Allocation | Automatic | Manual |
| Speed | Fast | Slower |
| Structure | LIFO | Random |
| Lifetime | Temporary | Long-term |
| Used for | Functions | Dynamic memory |
✔ Memory is divided into text, data, heap, stack ✔ Stack stores function calls and local variables ✔ Each function uses Activation Record ✔ Stack follows LIFO order ✔ Stack allocation is fast and automatic ✔ Used heavily in recursive function calls
Storage organization refers to how memory is divided into segments like text, data, heap, and stack during program execution. Stack allocation of space is a runtime memory management technique where function calls are handled using a stack, and each call creates an activation record containing parameters, return address, local variables, and control information.
| Concept | Description |
|---|---|
| Storage organization | Memory layout of program |
| Stack | Stores function calls |
| Heap | Dynamic memory |
| Data segment | Global/static variables |
| Activation record | Function call memory block |
| Stack allocation | LIFO memory management |
Open this section to load past papers