What is techniques of storage allocation in compiler design?

Compiler DesignProgramming LanguagesComputer Programming

There are various storage allocation techniques are as follows −

Static Allocation

It is the simplest allocation scheme in which allocation of data objects is done at compile time because the size of every data item can be determined by the compiler.

Recursive Subprogram and Arrays of adjustable length are not permitted in a language. In static allocation, the compiler can decide the amount of storage needed by each data object. Thus, it becomes easy for a compiler to identify the address of these data in the activation record.

FORTRAN uses this kind of storage allocation strategies.

Advantages

  • It is easy to implement.
  • It allows type checking during compilation.
  • It eliminates the feasibility of running out of memory.

Disadvantages

  • It is incompatible with recursive subprograms.
  • It is not possible to use variables whose size has to be determined at run time.
  • The static allocation can be completed if the size of the data object is called compile time.

Dynamic Allocation (Stack Allocation)

The stack allocation is a runtime storage management technique. The activation records are pushed and popped as activations begin and end respectively.

Storage for the locals in each call of the 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 the call is made.

It can be determined the size of the variables at a run time & hence local variables can have different storage locations & different values during various activations.

It allows recursive subprograms.

ALGOL language uses this strategy.

On each execution of a procedure, An Activation Record is generated, which contains information like Local data, actual parameter, return value, return address of a procedure. The Activation Record for that procedure is saved onto the stack.

If procedure A calls B, and then B calls C, then stack allocation will be

Advantages

  • It supports recursion.
  • It creates a data structure for the data item dynamically.

Advantages

  • Memory Addressing can be done using pointers & index Registers.

Heap Storage Allocation

It enables the allocation of memory in a Non-nested design. Storage can be allocated & freed arbitrarily from an area known as Heap.

Heap Allocation is helpful for executing data whose size varies as the program is running.

Heap is maintained as a list of free space called free space list.

Advantages

A large block of storage can be partitioned into smaller blocks at run time.

Disadvantages

It creates the problem of fragmentation.

raja
Updated on 08-Nov-2021 10:14:45

Advertisements