13,231 views
36 36 votes

Faster access to non-local variables is achieved using an array of pointers to activation records called a 

  1. stack
  2. heap
  3. display
  4. activation tree

2 Answers

Best answer
54 54 votes

Correct Option: C

Properties of displays    

  1. Use a pointer array to store the activation records along the static chain.
  2. Fast access for non-local but may be complicated to maintain.
  3. Calling a subprogram in the same level – simply replace and restore.
  4. Calling a subprogram in the higher level – add an entry and may need to save the old pointers.
  5. Calling a subprogram in the lower level – shrink the pointer and restore it when the subprogram returns.

http://users.dickinson.edu/~wahlst/356/ch10.pdf

• edited by
1 1 vote

The data structure used to enable efficient access to non-local variables in block-structured languages that support nested procedures (such as Pascal or Ada) is the display. A display is an array of pointers to activation records, where each entry corresponds to a static nesting level. If the maximum static depth of nesting in a program is $ d $, then the display is an array $ \text{display}[0 \ldots d] $ such that:

$$
\text{display}[i] = \text{pointer to the activation record of the most recent invocation at static level } i.
$$

When a procedure executing at static level $ k $ needs to access a variable defined at an outer static level $ i < k $, it retrieves the variable using:

$$
\text{display}[i] + \text{offset of variable}.
$$

This mechanism provides $ O(1) $ access time to non-local variables, regardless of how deeply nested the current procedure is in the call chain.

Consider the following program structure:

  1. Program $ \text{Main} $ (static level 0) declares variable $ a $.
  2. Procedure $ P $ (static level 1) declares variable $ b $.
  3. Procedure $ Q $, nested inside $ P $ (static level 2), executes the statement $ a := a + b $.

During execution of $ Q $, the display contains:

  • $ \text{display}[0] $ pointing to $ \text{Main} $'s activation record,
  • $ \text{display}[1] $ pointing to $ P $'s activation record,
  • $ \text{display}[2] $ pointing to $ Q $'s own activation record.

Thus, $ Q $ accesses $ a $ via $ \text{display}[0] $ and $ b $ via $ \text{display}[1] $, without traversing a static link chain.

Other options are unsuitable:

  • The stack holds activation records but does not by itself support direct indexed access to outer scopes.
  • The heap is used for dynamically allocated data, not for lexical scoping.
  • The activation tree is a conceptual model of procedure calls, not a runtime data structure.

Therefore, the correct answer is:

$$
\color{hotpink} \boxed{\text{C. display}}
$$

Answer:
Position:
Show:

Related questions

22 22 votes
2 answers 2 answers
8.6k
8.6k views
Kathleen asked Sep 25, 2014
8,598 views
A linker reads four modules whose lengths are $200, 800, 600$ and $500$ words, respectively. If they are loaded in that order, what are the relocation constants?$0, 200, ...
35 35 votes
3 answers 3 answers
12.9k
12.9k views
Kathleen asked Sep 25, 2014
12,945 views
In a resident &ndash; OS computer, which of the following systems must reside in the main memory under all situations?AssemblerLinkerLoaderCompiler
34 34 votes
4 answers 4 answers
12.6k
12.6k views
Kathleen asked Sep 25, 2014
12,582 views
What is the result of the following program?program side-effect (input, output); var x, result: integer; function f (var x:integer):integer; begin x:x+1;f:=x; end begin x...
27 27 votes
1 answers 1 answer
15.1k
15.1k views
Kathleen asked Sep 26, 2014
15,096 views
Let the attribute ‘$val$’ give the value of a binary number generated by $S$ in the following grammar:$S \rightarrow L.L \mid L$$L \rightarrow LB \mid B$$B \rightarrow 0 ...