Storage Allocation




Storage Allocation

  • There are basically three storage-allocation strategy is used in each of the three data areas in the organization.
    • Static allocation lays out storage for all data objects at compile time.
    • Stack allocation manages the run-time storage as a stack,
    • Heap allocation allocates and de-allocates storage as needed at run time from a data area known as a heap.
 Storage Allocation

Storage Allocation

Static Allocation

  • In static allocation, names are bound to storage as the program is compiled, so there is no need for a run-time support package.
  • Since the bindings do not change at run time, every time a procedure is activated, its names are bound to the same storage locations.
  • The above property allows the values of local names to be retained across activations of a procedure. That is, when control returns to a procedure, the values of the locals are the same as they were when control left the last time.
  • From the type of a name, the compiler determines the amount of storage to set aside for that name.
  • The address of this storage consists of an offset from an end of the activation record for the procedure.
  • The compiler must eventually decide where the activation records go, relative to the target code and to one another.

Limitation of Static Allocation

  • The size of a data object and constraints on its position in memory must be known at compile time.
  • Recursive procedures are restricted, because all activations of a procedure use the same bindings for local names.
  • Dynamic allocation is not allowed. so data structures cannot be created dynamically.
 Static Allocation

Static Allocation

Stack Allocation

  • Stack allocation is based on the idea of a control slack.
  • A stack is a Last In First Out (LIFO) storage device where new storage is allocated and deallocated at only one ``end'', called the top of the stack.
  • Storage is organized as a stack, and activation records are pushed and popped as activations begin and end, respectively.
  • Storage for the locals in each call of a procedure is contained in the activation record for that call. Thus locals are bound to fresh storage in each activation, because a new activation record is pushed onto the stack when a call is made.
  • Furthermore, the values of locals are detected when the activation ends. that is, the values are lost because the storage for locals disappears when the activation record is popped.
  • At run time, an activation record can be allocated and de-allocated by incrementing and decrementing top of the stack respectively.
 Stack Allocation

Stack Allocation

Heap Allocation

  • The deallocation of activation records need not occur in a last-in first-out fashion, so storage cannot be organized as a stack.
  • 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.
  • Heap is an alternate for stack.
 Heap Allocation

Heap Allocation



Related Searches to Storage Allocation