Run-Time Memory Organization

 
 
Operating System (Resident and By Request Sections)
Run-Time HEAP 
(used for memory allocated through pointers and references)
 
Run-Time Stack
(used for management of function calls)

Run-Time Stack is divided into chunks of memory called Activation Records , each dedicated to a function call that occured during the execution time and managed by LIFO strategy. The structure of an activation record is as follows :
 
Dynamic Link (Return Address)
Static Link (Address of Global Items)
PSW (Program Status Word)
(encoded info. about the system at the moment of the call)
Function's Parameters
(copies of the actual arguments for "value parameters",
copies of the addresses of the actual arguments for "reference parameters")
Function's Local  Variables

For instance, the quicksort algorithm working on the array 5, 12, 3, 2, 9, 12, 8, 7, 11, 4 gets invoked first as qs(0,9) to sort the entire array, which triggers recursive calls and corresponding activation records as follows:
 
Return Address after qs(0,9) is done
Static Link for qs(0,9)
PSW for qs(0,9)
Parameters
left_end (=0)
right_end (=9)
Local Variables

 
l (=6 after the exit from do while loop)
r (=5 after the exit from do while loop)
temp
pivot
AR for qs(0,9)

After qs(0,9) makes a call to qs(0,5) the stack looks as follows :
 
AR for qs(0,5)
Return Address after qs(0,9) is done
Static Link for qs(0,9)
PSW for qs(0,9)
Parameters
left_end (=0)
right_end (=9)
Local Variables

 
l (=6 after the exit from do while loop)
r (=5 after the exit from do while loop)
temp
pivot
AR for qs(0,9)