Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(a) Suppose variables i and j are integer pointers and initialized to NULL. Given the following piece of codes in C-like syntax. i = (int
(a) Suppose variables i and j are integer pointers and initialized to NULL. Given the following piece of codes in C-like syntax. i = (int *) malloc (sizeof (int)); j = i; i = (int *) malloc (sizeof (int)); j = 1; Trace the execution of the above piece of codes line by line, and accompany your descriptions using memory diagrams. In particular, you should give the values of the reference counters of the two pieces of dynamically created memory, and explain how the first piece is detected to be garbage at the end of execution. (b) Explain how the reference counter of the second piece of memory should be updated if another "j = i;" is appended to the end of the codes in part (a). (c) Use a simple memory diagram to illustrate a scenario in which garbages cannot be identified by the reference counter method. Give explanation. (d) Give two distinct implementation overheads of the reference counter method
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started