GATE / CS ARCHIVE

GATE CSE 2010 / QUESTION 14

Runtime heap allocation

Compiler Design · Runtime Environments & Parameter Passing · Full GATE CSE 2010 paper

GATE 2010, Q14 1 mark · MCQ
Report issue

Runtime Environments & Parameter Passing

Question 14, GATE 2010: Which class of programming languages necessarily needs heap allocation in its runtime environment?
Options: (A) Languages supporting recursion; (B) Languages using dynamic scoping; (C) Languages allowing dynamic data structures; (D) Languages using global variables.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Dynamically created data structures can have sizes and lifetimes unrelated to the last-in-first-out nesting of procedure activations, so their runtime storage requires heap-style allocation in the standard implementation model. Recursion and dynamic scope can be supported with activation stacks; global variables can use static storage. C is the intended distinction. A language implementation may realize the allocator through a preallocated arena, but that is still heap-style management rather than a counterexample to the storage-lifetime distinction.

A recursive call creates a new activation record that can be popped when the call returns, so recursion alone needs a stack, not a heap. A linked node returned to a caller may have to survive its creator’s return and be freed in an arbitrary order. That non-LIFO lifetime is the key distinction tested by dynamic data structures.

Original paper, page 3