Behold the following implementation of malloc() and
free().
char *malloc(int size) { return sbrk(size); } void free(char *s) { return; }Listed on the right are some possible outcomes of a program that uses this version of malloc(). |
|
For each part below, circle all of the outcomes listed above that apply. Assume that sbrk() initially returns a multiple of 8, and that our pointers are 4 bytes.
Part i: Suppose we write a program that sorts the lines of a file using the fields library, the red-black tree library, and strdup(). What outcomes apply when this program is executed on a large text file?
Part ii: Suppose we write a program that reads integers from a file, and sorts them using the red-black tree library. What outcomes apply when this program is executed on a large text file?
Part iii: Suppose we write a program that reads doubles from a file, and sorts them using the red-black tree library. What outcomes apply when this program is executed on a large text file?
Part iv: Suppose cat were compiled with the malloc() above. What outcomes apply when cat is executed with a huge input file?
Part v: Suppose netscape were compiled with the malloc() above. What outcomes apply when netscape is given its normal usage?
Part vi: The following program is compiled and executed:
main() { JRB t; t = make_jrb(); while(1) { sleep(1); if (!jrb_empty() && lrand48() % 2 == 0) { jrb_delete_node(jrb_first(t)); } else { jrb_insert_int(t, lrand48(), JNULL); } } }