storage allocation strategies

11
STORAGE ALLOCATION STRATEGIES Sreel aj

Upload: vsunny488

Post on 11-Apr-2015

3.980 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Storage allocation strategies

STORAGE ALLOCATION STRATEGIES

Sreelaj

Page 2: Storage allocation strategies

DIFFERENT WAYS TO ALLOCATE OBJECTS

Static allocation – allocates storage at compile time

Stack allocation - manages run time storage as stack

Heap allocation – allocates and de-allocates storage area as needed at runtime.

Page 3: Storage allocation strategies

STATIC ALLOCATION Names are bound to storage locations This property allows values of local names to be

retained across the complete program At the compile time compiler determines how

much storage should be allocated for each object.

At the compile time, compiler determines the following

1 . Where the activation records go, relative to target code 2 . Where the addresses should be filled in the records 3 . The address for the procedure calls

Page 4: Storage allocation strategies

LIMITATIONS

Size & position of data objects must be known at compile time.

Recursive procedures are restricted. Data objects cannot be created dynamically.

E.g.: Fortran

Page 5: Storage allocation strategies

FORTRAN

A Fortran compiler might place the activation record for a procedure together with the code for that procedure.

In some systems it is possible to use link editor to link activation records and executable code.

Page 6: Storage allocation strategies

STACK ALLOCATION

Storage is organized as a stack Activation records are pushed and popped as

activation begin and end Storage for locals in each call of a procedure

is contained in the activation record for that call

The values of locals are deleted when the activation ends

A register can be used to mark the top of stack. At run time an activation record can be allocated and de-allocated by incrementing and decrementing register.

Page 7: Storage allocation strategies

CALLING SEQUENCES

For implementing procedure calls. A call sequence allocates an activation

record and entries information into its fields. A return sequence restores the state of the

machine so the calling procedure can continue execution.

Page 8: Storage allocation strategies

CALLING SEQUENCES

The code in a calling sequence is often divided between the calling procedure and the procedure it calls

Usually fixed size fields are placed in the middle

Temporary fields are often stored after local data to a procedure so that changes in its size will not affect the offsets of data objects

Page 9: Storage allocation strategies

DIVISION OF TASKS BETWEEN CALLER AND CALLEE

PARAMETERS & RETURN VAL

Control link

Temporaries & local data

Control link

Temporaries & local data

PARAMETERS & RETURN VAL

Callers activation record

Callee’s activation record

Page 10: Storage allocation strategies

THE CALLING SEQUENCE

The caller evaluates the actuals The caller stores a return address & old value

of stack in its activation & increments pointer to new position

Callee saves register values and other information

Callee initializes its local data & begins execution

Page 11: Storage allocation strategies

A POSSIBLE RETURN SEQUENCE

The callee places a return value next to activation record of the caller

Using info on activation record , the callee restores stack pointer & other registers & branches to the return address in callers code

The caller can copy the returned value to its own activation record & use it to evaluate an expression.