CS 3304 Homework Assignment 6

25 Points
Due: 02/28 at the start of class

Note: The following instructions are repeated from the Homework Dates/Guidelines page:

Your solutions for each homework assignment must be prepared with a word processor (e.g., LaTeX or Word), and are due at the beginning of class on the due date specified unless otherwise noted on the assignment itself.

Note that all homework problems taken from the text are in the Problem Sets. Do not turn in solutions to Review Questions by mistake!

Also, remember that the 5th Edition text includes a new chapter--Chapter 4. All chapter numbers in homework assignments are from the 5th Edition, so students with earlier versions of the text must remember that in their books, the chapter numbers are off by one. If you have an earlier version of the text, you are still responsible for solving the correct problems.

Complete each of the following problems:

  1. Chapter 5, Problem 5 (Chapter 4 in 4th ed.)

  2. Chapter 6, Problem 14 (Chapter 5 in 4th ed.)

  3. Compare the following three approaches of avoiding dangling pointers from the points of view of safety and implementation cost:

    1. tombstones

    2. locks-and-keys

    3. reference counting

      In reference counting, a heap-allocated object contains an additional cell that is used to store a count of the number of pointers referring to the object. On initial allocation, this count is set to one. Each time a pointer is copied, the reference count for the previously-pointed-to object is decremented and the reference count for the new destination is incremented. When one calls "delete", the reference count is decremented, but the object is only deallocated if the new reference count is zero.