Question: (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

(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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!