Storage Organization
Duration: 38 min
This video lesson is available to enrolled students.
Enroll to watch — Coal India Management Trainee (CS) Recruitment 2026
AI summary & chapters
AI Summary
An AI-generated summary of this video lecture.
This lecture on Storage Organization explains how compilers and runtime systems partition program memory into static, stack, and heap regions based on variable lifetime. The instructor uses a C example with global variables and local function variables to map declarations to memory areas, then analyzes a recursive factorial program. A call tree and stack-frame diagram show how each recursive call pushes an activation record containing its own local variable, while return values unwind the stack. A static-variable variant demonstrates that static memory is allocated once at compile time, contrasting with per-call stack allocation. The lecture concludes by summarizing static and stack storage properties: static memory is allocated once but does not support recursion, whereas stack allocation supports recursion through automatic push/pop of activation records but cannot represent dynamic data structures.
Chapters
0:00 – 2:00 00:00-02:00
The lecture opens with the slide titled “Storage Organization,” stating that during program execution the compiler and runtime system organize memory into different areas according to data lifetime and storage requirements. The instructor lists the three major allocation strategies: “1. Static Storage Allocation,” “2. Stack Storage Allocation,” and “3. Heap Storage Allocation.” A C example is begun on the board, including “int x = 10;” and “int main()”, with local declarations such as “int y=40, z=30;” and the assignment “y = y + z;”, setting up a concrete program for mapping variables to memory regions.
2:00 – 5:00 02:00-05:00
The instructor annotates the C program to distinguish storage classes. The global declaration “int x = 10;” is labeled “Static/Global,” while the body of main is boxed and marked “Stack.” A second function, shown as “int A()”, is added with its own local variables, illustrating that each function’s locals belong to stack storage. The board code includes lines such as “y = d + z;” and the instructor circles declarations to connect source-level variables with their runtime memory locations.
5:00 – 10:00 05:00-10:00
The example transitions to a recursive factorial problem. A new slide asks, “Q. Consider the following recursive factorial function:” and shows “int fact(int n)”, base case “if (n==0) return 1;” or later “if (n == 1) return 1;”, and recursive step “return n * fact(n-1);”. The main function contains “int n=5;” and “printf("Factorial = %d", fact(n));”. The instructor underlines the call to emphasize that main invokes fact(5), preparing a stack-frame analysis of recursion.
10:00 – 15:00 10:00-15:00
A call tree is drawn from “main()” to “fact(5)” and then “fact(4)”, with a return annotation reading “- Return (n * fact(4))”. On the right, a green stack diagram shows activation frames for fact calls holding local values such as n = 5 and n = 4, with addresses like 2000 and 3000. The instructor traces how each recursive call creates a new stack frame before the base case is reached, demonstrating that local variables are allocated per activation record.
15:00 – 20:00 15:00-20:00
The full factorial call sequence is shown, with stack frames for fact(2), fact(3), fact(4), and fact(5) above main, each containing a boxed “n” value. The base-case line is circled with a green ring and marked “1 == 1 ✓”. As the stack unwinds, return values are calculated as 1, 2, 6, 24, and 120. A static-variable variant is introduced with “static int n; // Static memory: allocated only ONCE at compile time,” and a single separate “Static” block is drawn to contrast one-time allocation with repeated stack-frame creation.
20:00 – 25:00 20:00-25:00
The instructor examines a modified factorial function “int fact(int val)” containing “n = val;”, “if (n == 1) return 1;”, and “return n * fact(n - 1);”. A green checkmark appears beside the base-case return, while “static int n;” is crossed out with a red X in one annotation. Stack frames for fact(1) through fact(5) are drawn with “Val” boxes and addresses such as 2000 or 1000. A “Static/Global Area” box shows variable n, with a red X and note “3 != 1”, highlighting why static storage is unsuitable for recursive state.
25:00 – 30:00 25:00-30:00
The board continues to show the factorial program with “if (n == 1)” circled and frames labeled fact(1) through fact(5). The instructor points to the call tree showing “Return (n*fact(4))” and the value “5 * 4”, illustrating multiplication during stack unwinding. A slide titled “Static Storage Allocation” states that memory created at compile time is allocated only once, with a “Drawbacks” list including “Recursion is not supported.” A following “Stack Storage Allocation” section lists bullets such as “Recursion is supported.” and “Push and pop operations are performed automatically.”
30:00 – 35:00 30:00-35:00
The lecture shifts to summarizing stack storage properties. The board lists “Stack Storage Allocation” bullets, including the underlined statement “When a function is called, its activation record is pushed onto the stack.” Red teaching marks appear: a check beside “Recursion is supported.” and a cross beside “Dynamic data structures are not supported.” These annotations distinguish what stack allocation can and cannot represent, reinforcing the earlier factorial example where each call required its own activation record.
35:00 – 38:11 35:00-38:11
The final segment reviews the drawbacks of stack storage. A “Drawbacks” section is shown with a green handwritten note reading “loop” and an arrow in the top-right corner, likely indicating loop-related limitations or context. The board returns to “Storage Organization” with the list beginning “1. Static Storage Allocation.”, tying the detailed factorial and static-variable examples back to the three major allocation strategies introduced at the start of the lecture.
The central teaching thread is mapping C declarations and function calls to memory regions. The instructor first establishes the three allocation strategies, then uses a simple program with global and local variables to show static/global versus stack storage. The recursive factorial example becomes the main demonstration: each call pushes an activation record containing its own local variable, and return values are computed while frames pop. The static-variable variant provides the key contrast: a single compile-time allocated block cannot hold separate values for nested recursive calls, which is why recursion requires stack storage. The concluding slides formalize this by stating static memory is allocated once and does not support recursion, while stack allocation supports recursion through automatic push/pop but cannot represent dynamic data structures.