You are on page 1of 8

Allocation Strategies

Variable Length Data
 A common strategy for handling variable-length data is by using
of local arrays.

 The storage for these arrays is not part of the activation record:
only a pointer to the beginning of each array appears in the
activation record.

 The relative addresses of these pointers are known at compile

time, so the target code can access array elements through the
Dangling References
 A dangling reference occurs when there is a reference to storage that has
been deallocated.

 It’s a logical error to use dangling reference , since the value of the
deallocated storage is undefined.

 If that storage may later be allocated to another datum, mysterious bugs

can appear in programs with dangling references.
int *p;
p= dangle();
int *dangle()
int i=23;
return &i;
Heap Allocation
Heap allocation is necessary when,

1. The values of local names must be retained when an activation ends.

2. A called activation outlives the caller.

Heap allocation parcels out pieces of contiguous storage, as needed for

activation records or other objects. Pieces may be deallocated in any order , so
over time the heap will consist of alternate areas that are free and in use.
Thank You…