Memory Allocation: block-structured language
- The block is a sequence of statements containing the local data and declarations which are enclosed within the delimiters.
- Similarly, The delimiters mark the beginning and the end of the block. There can be nested blocks for ex: block B2 can be completely defined within the block B1.
- A block-structured language uses dynamic memory allocation.
- Moreover, Finding the scope of the variable means checking the visibility within the block
- Following are the rules used to determine the scope of the variable:
1. Variable X accessed within the block B1 if it can be accessed by any statement situated in block B1.
2. Variable X accessed by any statement in block B2 and block B2 situated in block B1.
- Similarly, There are two types of variable situated in the block-structured language
1. Local variable
2. Non-local variable
To understand local and non-local variable consider the following example
- Procedure Local variables Non local variables
- Variables x, y and z local variables to procedure A but those are non-local to block B and C because this variable not defined locally within the block B and C but are accessible within these blocks.
- Automatic dynamic allocation implemented using the extended stack model.
- Memory Allocation: block-structured language
- Moreover, Each record in the stack has two reserved pointers instead of one.
- Similarly, Each stack record accommodates the variable for one activation of a block, which we call an activation record (AR).
- The first reserved pointer in block’s AR points to the activation record of its dynamic parent.
This called dynamic pointer and the address 0 (ARB).
- Moreover, The dynamic pointer used for de-allocating an AR.
Following example shows memory allocation for the program given below.
- Similarly, Access to non local variable implemented using the second reserved pointer in AR. This pointer which the address 1 (ARB) called the static pointer.