- Three important tasks of memory allocation are:
1. Determine the amount of memory required to represent the value of a data item.
2. Use an appropriate memory allocation model to implement the lifetimes and scopes of data items.
3. Determine appropriate memory mappings to access the values in a non-scalar data item, e.g. values in an array.
- Memory allocation is mainly divided into two types:
1. Static binding
2. Dynamic binding
Static memory allocation
- In static memory allocation, memory allocated to a variable before the execution of a program begins.
- Static memory allocation typically performed during compilation.
- No memory allocations or deallocation actions performed during the execution of a program. Thus, variables remain permanently allocated
Dynamic memory allocation
- In dynamic memory allocation, memory bindings established and destroyed during the execution of a program
- Dynamic memory allocation has two flavors’-automatic allocation and program controlled allocation.
- In automatic dynamic allocation, memory allocated to the variables declared in a program unit when the program unit entered during execution and is deallocated when the program unit is exit. Thus the same memory area may be used for the variables of different program units
- Moreover, In program controlled dynamic allocation, a program can allocate or deallocate memory at arbitrary points during its execution.
- It obvious that in both automatic and program controlled allocation, the address of the memory area allocated to a program unit cannot be determined at compilation time.
Intermediate code of expression
- There are two types of intermediate representation
1. Postfix notation
2. Three address code.
1) Postfix notation
- Postfix notation is a linearized representation of a syntax tree.
- Moreover, it a list of nodes of the tree in which a node appears immediately after its children
- the postfix notation of x=-a*b + -a*b will be x a –b * a-b*+=
2) Three address code
- In three address code form at the most three addresses used to represent a statement.
Also, The general form of three address code representation is -a:= b op c
Where a,b or
the operands that can be names, constants.
- For the expression like a = b+c+d the three address code will be
- Moreover, Here t1 and t2 the temporary names generated by the compiler. There are most three addresses allowed. Hence, this representation is three-address code.
- There three representations used for three code such as quadruples, triples and indirect triples.