Presentation is loading. Please wait.

Presentation is loading. Please wait.

Run-Time Storage Organization

Similar presentations


Presentation on theme: "Run-Time Storage Organization"— Presentation transcript:

1 Run-Time Storage Organization

2 Introduction We need to relate the static source text of a program to the actions that must occur at run time We need to allocate and manage the memory used by the program (static and dynamic)

3 Memory Allocation Techniques
Static Allocation Stack Allocation Heap Allocation Code Static Data Stack Heap

4 Static Allocation The number and size of all objects to be allocated is known at compile time It is used for: Global variables that are fixed in size and accessible throughout program execution Program literals (constants) Program code

5 Stack Allocation Information needed by a single execution of a routine (a procedure, function or method) is managed using an activation record or frame An activation record contains local variables, parameters, return address, etc. Activation records are pushed and popped as functions calls begin and end

6 Parameter Passing Call-by-value can be implemented as follows:
A formal parameter is treated like a local variable, so the storage for the formal is in the activation record of the called routine The caller evaluates the actual parameters and places their values in the storage for the formals Call-by-reference The caller passes to the called procedure a reference to the storage address of each actual parameter

7 Heap Allocation The heap is used to store data which can be allocated and freed at any time and in any order Deallocation is either manual or automatic (garbage collection) The heap typically becomes fragmented during use


Download ppt "Run-Time Storage Organization"

Similar presentations


Ads by Google