How are storage addresses typically allocated for each of these types of variable?

Explain why some programming languages require automatic memory management
March 21, 2023
Can static linking be used to implement a language
March 21, 2023

How are storage addresses typically allocated for each of these types of variable?

COMPUTER SCIENCE TRIPOS Part IB – 2012 – Paper 3
Compiler Construction (DJG)
(a) Define the following forms of variable: [1 mark each]
(i) statically allocated global variable
(ii) local variable (to a function)
(iii) free variable
(b) In an object-oriented language, which of the above three terms best describes a
field? [1 mark]
(c) How are storage addresses typically allocated for each of these types of variable?
Describe the stage/pass of the compiler that makes the allocation and also
describe any changes made by the operating system linker or loader. [3 marks]
(d) What addressing mode or sequence of instructions is typically used in compiled
code to read (or write) each of the variable forms from part (a)?
[1, 1, 4 marks]
(e) With dynamic storage allocation, how does the memory manager ‘new’ operator
know how much memory to allocate? Discuss both compilation to machine code
and execution on a VM. [2 marks]
(f ) Why is garbage collection easier to implement in strongly-typed languages
(compared with weakly-typed languages)? [1 mark]
(g) What overheads does allocating arrays and class objects on the stack cause
compared with placing them on the heap? What are the advantages and
disadvantages of each method? [4 marks]