Вы находитесь на странице: 1из 11

STORAGE ALLOCATION

STRATEGIES

Sreel
aj
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.
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
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
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.
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.
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.
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
DIVISION OF TASKS BETWEEN CALLER
AND CALLEE

PARAMETERS & RETURN VAL


Callers activation
Control link record

Temporaries & local data

PARAMETERS & RETURN VAL


Callee’s activation
Control link
record

Temporaries & local data


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
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.

Вам также может понравиться