STORAGE ALLOCATION STRATEGIES
- Static Allocation: It is for all the data objects at compile time.
- Stack Allocation: In this a stack is used to manage the run time storage. For example recursive calls make use of this area.
- Heap Allocation: In this a heap is used to manage the dynamic memory allocation.
- The size of data objects is known at compile time.
- The names of these objects are bound to storage at compile time only and such an allocation of data objects is done by Static Allocation.
- The binding of name with the amount of storage allocated do not change at run time. Hence the name of this allocation is Static Allocation.
- In this the compiler can determine the amount of storage required by each data object and therefore it becomes easy for a compiler to find the address of these data in the activation record.
- At compiler time compiler can fill the address at which the target code can find the data it operates on.
- FORTRAN uses the Static Allocation.
Limitation of static allocation
- The Static Allocation can be done only if the size of data object is known at compile time.\
- The data structures cannot be created dynamically. In the sense that, the Static Allocation cannot manage the allocation of memory at run time.
- Recursive procedures are not supported by this type of allocation.
- In this the storage is organized as stack .This stack is also called control stack.
- As activation begins the activation records are pushed onto the stack and on completion of this activation the corresponding activation records can be popped.
- The locals are stored in the each activation record. Hence locals are bound to corresponding activation record on each fresh activation.
- The data structures can be created dynamically for Stack Allocation.
Limitation of stack allocation
The memory addressing can be done using pointers an index registers. Hence this type of allocation is slower than Static Allocation
- If the values of non local variables must be retained even after the activation record then such a retaining is not possible by Stack Allocation. This limitation of Stack Allocation is because of its Last in First Out nature. For retaining of such local variables Heap Allocation strategy is used.
- The Heap Allocation allocates the continuous block of memory when required for storage of activation records or other data object, this allocated memory can be deallocated when activation ends. This deallocated space can be further reused by heap manager.
- The efficient heap management can be done by
- Creating a linked list for the free blocks and when any memory is deallocated that block of memory is appended in the linked list.
- Allocate the most suitable block o memory from the linked list i.e. use best fit technique for allocation of block.