Sie sind auf Seite 1von 6

Memory allocation concept

 Memory allocation is the process of setting aside sections of memory in a program to


be used to store variables, and instances of structures and classes.
 There are two kinds of variables
1) Variable constituting automatic data : It is created automatically when the
block containing its declaration is entered during the program’s execution
and destroyed when block is exited.
2) Variable constituting program controlled data : It is created and destroyed
through execution of special statements such as calloc and free.
 Memory allocation involves three important tasks:
1) Determining the amount of memory required for storing the value of data item.
2) Using an appropriate memory allocation model for implementing the lifetime of
data items and scope rules of the language.
3) Developing appropriate memory mappings for accessing values stored in data
structure.

Memory binding

A memory binding is an association between the ‘memory address’ attribute of a data


item and the address of memory area. Memory allocation is an activity of performing
memory binding. Memory binding can be static or dynamic in nature, giving rise to static and
dynamic memory allocation models.

Types of memory allocation

1) Static memory allocation


In static memory allocation memory is allocated to a variable before the execution of
program begins. It requires that binding of attributes that influence memory
requirements of data item. E.g. types and dimensions of variables should be
performed before or during compilation.
Static allocation is used for programming languages like fortran.
2) Dynamic memory allocation
In dynamic memory allocation memory bindings are established and destroyed during
the execution of a program, hence binding of attributes such as types and dimensions
of variables can also be performed during execution of program.
Dynamic allocation is used in block structured languages like C, CPP, Java

Working of compiler

A compiler is a computer program that transforms source code written in a high-level


programming language into a lower level language (assembly language).

Basically, a compiler consists the following phases:

1)Lexical Analysis

2) Syntax Analysis

3) Semantic Analysis

4) IR Generation

5) IR Optimization

6) Code Generation

7) Optimization.
Given a sample program:

The following shows the output of each phase.

1. Lexical Analysis
Convert a program into sequence of tokens.
2. Syntax Analysis
Recover the structure described by using series of tokens from previous scanner.

3. Semantic Analysis
Ensures program has a well-defined meaning.
4. IR Generation

5. IR Optimization

6. Code Generation

7. Optimization

Das könnte Ihnen auch gefallen