Starting from:

$29

Homework 7: Memory Management

Programming Languages Concepts

Homework 7: Memory Management

Submission: Please submit your homework via Canvas. It’s okay if you
submit a scanned version of your on-paper answers, but please make sure
your scanned version is legible.
1. (4 points) For each of the following Scheme lists, draw its memory
representation using atom and cons cells:
(a) ’(everyday (is a winding) road)
(b) ’((everyday) (is) (a) (winding) (road))
2. (4 points) For each of the following Scheme expressions, draw the
memory representation after its evaluation:
(a) (cons (cons ’a (list ’b ’c)) (list ’b ’c))
(b) ((lambda (x) (cons (cons ’a x) x)) (list ’b ’c))
3. We have a Scheme program below:
(define lst ’(Scheme (is fun)))
(define lst2 (car (cdr lst)))
(set-car! lst2 ’has)
(a) (2 points) Draw the memory layout in terms of cells for each
execution step of the above program. Assume Garbage Collection
does not run in intermediate steps.
(b) (1 point) What is the value of lst at the end?
(c) (1 point) Suppose the system decides to perform a Mark-andSweep Garbage Collection at the end, which memory cells would
be recycled?
4. (3 points) C and C++ do not have garbage collection built in. Find out
whether if there is an external package that provides garbage collection
to C/C++ programmers. If there is, understand and describe briefly
how a C/C++ programmer should use this package.
1

More products