Chapter 6: Runtime System

Heap Allocation

. Stack allocation cannot be used if:

- The values of the local variables must be retained when an activation ends

- A called activation outlives the caller

. In such a case de-allocation of activation record cannot occur in last-in first-out fashion

. Heap allocation gives out pieces of contiguous storage for activation records

There are two aspects of dynamic allocation -:

. Runtime allocation and de-allocation of data structures.

. Languages like Algol have dynamic data structures and it reserves some part of memory for it.

If a procedure wants to put a value that is to be used after its activation is over then we cannot use stack for that purpose. That is language like Pascal allows data to be allocated under program control. Also in certain language a called activation may outlive the caller procedure. In such a case last-in-first-out queue will not work and we will require a data structure like heap to store the activation. The last case is not true for those languages whose activation trees correctly depict the flow of control between procedures.