Unit-3.2 Run-time Storage Management
Compiler Design and Construction (CSC352)
Unit 3.2: Run-time Storage Management
Prepared By: Manila Tiwari
B.Sc. CSIT 6th Sem
Chapter 3.2 Contents
Content Overview: Run-time Storage Management
Prepared By: Manila Tiwari
B.Sc. CSIT 6th Sem
Run-time Storage Management
Activation Record
Definition: A block of memory used for managing information needed by a single execution of a procedure.
Key Operations: The following three-address statements are associated with the run-time allocation and de-allocation of activation records:
Call: Initiates a procedure call.
Return: Ends a procedure call and returns control.
Halt: Terminates the execution.
Action: A placeholder for other statements.
Prepared By: Manila Tiwari
B.Sc. CSIT 6th Sem
Activities During Procedure Call and Return
Caller’s Side:
Save registers for later use.
Arrange procedure arguments: Ensure arguments are accessible by the called procedure.
Call the procedure: Transfer control to the callee.
Callee’s Side:
Save registers for later use.
Allocate storage for automatic local variables and temporaries.
Copy return value to the appropriate place.
Throw away local variables and temporaries on return.
Restore saved registers before completing execution.
Prepared By: Manila Tiwari
B.Sc. CSIT 6th Sem
Storage Allocation Strategies
1. Static Storage Allocation
Definition: Memory is allocated at compile time.
Advantages:
Faster than dynamic allocation.
Disadvantages:
Does not support dynamic data structures.
Recursion is not supported.
Size of data must be known at compile time.
2. Stack Storage Allocation
Definition: Based on a Last In First Out (LIFO) storage mechanism.
Key Points:
New storage is allocated and de-allocated at the top of the stack.
Activation records are pushed and popped as activations begin and end.
Local variables are stored within the activation record of each procedure call.
Values are deleted when the activation ends.
Advantages:
Supports recursion; memory allocated on block entry.
Dynamically handles data structures.
Disadvantages:
Slower than static allocation due to memory addressing using pointers and index registers.
3. Heap Storage Allocation
Definition: Allows non-LIFO de-allocation of activation records.
Key Points:
Allocates pieces of contiguous storage as needed.
Storage can be de-allocated in any order, which may lead to fragmentation over time.
Serves as an alternative to stack allocation.
Prepared By: Manila Tiwari
B.Sc. CSIT 6th Sem
Conclusion
Thank You!
Prepared By: Manila Tiwari
B.Sc. CSIT 6th Sem