Professional Documents
Culture Documents
The above figure has consists of code, static data, stack and heap.
Activation Record:
a. A program is a sequence of instructions combined into a number of procedures.
b. Instructions in a procedure are executed sequentially.
c. The execution of a procedure is called its activation.
d. An activation record contains all the necessary information required to call a procedure.
e. An activation record may contain the following units (depending upon the source
language used).
Temporaries:
Local data:
Machine Status:
Machine Status Stores machine status such as Registers, Program Counter etc., before the
procedure is called.
Access link:
Access Link Stores the information of data which is outside the local scope.
Control link:
Control Link Stores the address of activation record of the caller procedure.
Actual Parameters:
Actual Parameters Stores actual parameters, i.e., parameters which are used to send input to the
called procedure.
Returned value:
The various storage allocation strategies to allocate storage in different data areas of memory are:
a. Static allocation
b. Stack allocation
c. Heap allocation.
Static allocation:
i. Storage is allocated for all data objects at compile-time.
ii. In static allocation, names are bound to storage as the program is compiled. Since the
bindings do not change at run time, every time a procedure is activated, its names are
bound to the same storage locations.
iii. This 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.
Stack allocation:
Example:
Heap Allocation:
a. The storage is allocated and de allocated at run-time from data are known as heap.
b. Heap allocation parcels out pieces of contiguous storage, as needed for activation records
or other objects.
c. Pieces may be de allocated in any order, so over time the heap will consist of alternate
areas that are free and in use.
7.3 Parameter Passing.
In general, there are two ways that a computer language can pass an argument to a subroutine.
a) Call-by Value
b) Call-by Reference.
a) Call-by Value:
This approach copies the value of an argument into the formal parameter of the subroutine.
Therefore, changes made to the parameter of the subroutine have no effect on the argument.
Example:
class Test {
i *= 2;
j /= 2;
} }
class CallByValue {
ob.meth(a, b);
b) Call-by Reference:
In this approach, a reference to an argument (not the value of the argument) is passed to
the parameter. Inside the subroutine, this reference is used to access the actual argument
specified in the call.
This means that changes made to the parameter will affect the argument used to call the
subroutine.
Example:
class Test {
int a, b;
Test(int i, int j) {
a = i;
b = j;
}
// pass an object
void meth(Test o) {
o.a *= 2;
o.b /= 2;
}
}
class CallByRef {
public static void main(String args[ ]) {
Test ob = new Test(15, 20);
System.out.println("ob.a and ob.b before call: " + ob.a + " " + ob.b);
ob.meth(ob);
System.out.println("ob.a and ob.b after call: " +ob.a + " " + ob.b);
}
}