1
h08
CS32 S17
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu section
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

h08: Memory

ready? assigned due points
true Thu 06/01 09:30AM Tue 06/06 09:30AM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the three lowest scores (if you have zeros, those are the three lowest scores.)


https://ucsb-cs32-s17.github.io/hwk/h08/

Reading: Memory, Reader pp 167-192

  1. (10 pts) Fill in the information in the header. The following are required to get the 10 "participation" points.
    • Filling in your name and umail address.
    • WRITING (not circling!) either 11, 12, 1, or 2, to indicate your discussion section (lab) meeeting time.

    Also: For paper submission PLEASE submit on ONE SHEET OF PAPER, double-sided if at all possible. If you must submit on two printed sheets write name on BOTH sheets and no staples, paperclips, or folded corners.

  2. Object files (.o files) are organized in standard way to allow the linker to organize multiple source files into a single executable. The reading discusses the five major sections of an object file. Below, list the order of the five major sections in an object file. Accompany each with a one-sentence description and example of what belongs there.
       
    • (3 pts)
    •  
    • (3 pts)
    •  
    • (3 pts)
    •  
    • (3 pts)
    •  
    • (3 pts)
  3. Answer each statement by stating the type of error that will result from these scenarios.
       
    1. (2 pts) Infinite recursive calls to a function:
    2.  
    3. (2 pts) Excessive allocations of memory using the new operator at runtime:
  4. (5 pts) Consider the function below, written by someone named B.C. Dull. B.C. Dull thinks this is a clever way to make something like a constructor for a Student object. B.C. tests the function on a few examples, and says: "looks ok to me". But B.C. has sown the seeds of destruction here. What is B.C.'s error? Explain briefly, but with just enough detail that the grader will have no doubt that you understand the situation fully.
    Student* makeStudent(std::string name, int perm) {
      Student s(name, perm);
      return &s;
    }
    
  5. (5 pts) Why does the C function malloc() return a void*?
  6. (5 pts) Why don't we use C allocation routines in C++? In other words, what benefits do new, new[], delete, delete[] offer that malloc(), realloc(), calloc(), free() don't?
  7. Franek describes various situations in which an attempt to do dynamic memory allocation in C++ can fail. Describe two of these.
       
    • (3 pts)
    •  
    • (3 pts)