CS520
Fall 2005
Programming Assignment 4
Due Sunday November 6


For Program 4 you should construct a memory allocator.

In Program 6 you will add the garbage collector to complete the system.

See the Program 3 specification for a description of the memInitialize and memAllocate functions.

To test your allocator, we will (for this assignment only) add the following function, which will deallocate allocated memory blocks:

memFree must be called with a pointer that points to the base of an allocated block, that is, with the pointer value that was originally returned by the call to memAllocate when the block was allocated. If a bad value is passed to memFree, it should print an appropriate error message to stderr and exit the program by calling exit(-1).

When a block is freed, its associated "finalize" function should be called, if one was specified when the block was allocated. This must be done before any word in the block is altered.

You should only use malloc in memInitialize. In particular, you cannot use it in memAllocate. Any control information for an allocated block must be stored in headers or footers attached to the block. You may have a few static global pointer variables that keep track of the location of the heap, but there should be no information in global memory that is specific to a particular allocated (or free) block.

Your program will be graded primarily by testing it for correct functionality. In addition, however, you may lose points if your program is not properly structured and documented.

Your code will be graded using an CIS Linux machine (e.g. turing.unh.edu) so be sure to test in that environment. I will use gcc to compile your code.

You should submit the source code for your memory allocator in a file called memAlloc.c.

Your program should be submitted for grading from a UNH CIS Linux machine (e.g. turing.unh.edu). To turn in this assignment, type:
~cs520/bin/submit prog4 memAlloc.c

Please submit only the above source file. Do not turn in any other files!

Submissions can be checked by typing:
~cs520/bin/scheck prog4

To receive full credit for the assignment, you must turn in your files prior to 8am on Monday November 7. Programming assignments may be handed in late at a penalty of 2 points for one day late, 5 points for two days late, 10 points for three days late, 20 points for four days late, and 40 points for five days late. No program may be turned in more than 5 days late.

Remember: as always you are expected to do your own work on this assignment.


Last modified on October 24, 2005.

Comments and questions should be directed to hatcher@unh.edu