labMalloc

 

Due Date

See the calendar for due date.

Objectives:

Description:

For this lab, you get to write your dynamic storage allocator for C programs, i.e., your own version of the malloc(), free() and realloc() routines. Start by copying labMalloc.tgz to a protected directory in which you plan to do your work. Then give the command: tar -xvf labMalloc.tgz. This will cause a number of files to be unpacked into the directory. The only file you will be modifying is mm.c. The mdriver.c program is a driver program that allows you to evaluate the performance of your solution. Use the command make to generate the driver code and run it with the command ./mdriver -V. (The -V flag displays helpful summary information.) When you have completed this lab, remove the object files with make clean and then make a tarball of the directory.

How to Work on this Lab

Your dynamic storage allocator will consist of the following four functions, which are declared in mm.h and defined in mm.c.
    int   mm_init( void);
    void *mm_malloc( size_t size);
    void  mm_free( void *ptr);
    void *mm_realloc( void *ptr, size_t size); 
The mm.c file provided, implements the simplest but still functionally correct malloc package possible. Using this as a starting place, modify these functions (and possibly define other private static functions), so that they obey the following semantics: These semantics match the semantics of the corresponding libc malloc(), realloc(), and free() routines. Type man malloc() in a terminal for complete documentation.

Heap Consistency Checker

Dynamic memory allocators are notoriously tricky beasts to program correctly and efficiently. They are difficult to program correctly because they involve a lot of untyped pointer manipulation. You will find it very helpful to write a heap checker that scans the heap and checks it for consistency. Some examples of what a heap checker might check are: Your heap checker will consist of the function int mm_check(void) in mm.c. It will check any invariants or consistency conditions you consider prudent. It returns a nonzero value if and only if your heap is consistent. You are not limited to the listed suggestions nor are you required to check all of them. You are encouraged to print out error messages when mm_check() fails. This consistency checker is for your own debugging during development. When you submit tarball, make sure to remove any calls to mm_check() as they will slow down your throughput. Make sure to put in comments and document what you are checking.

Support Routines

The memlib.c package simulates the memory system for your dynamic memory allocator. You can invoke the following functions in memlib.c:

The Trace-driven Driver Program

The driver program mdriver.c in the labMalloc.tgz distribution tests your mm.c package for correctness, space utilization, and throughput. The driver program is controlled by a set of trace files (that are found in /nfshome/hcarroll/public_html/3240/protected/traces/ on system64). Each trace file contains a sequence of allocate, reallocate, and free directions that instruct the driver to call your mm_malloc(), mm_realloc(), and mm_free() routines in some sequence. The driver and the trace files are the same ones used to grade your lab. The driver mdriver.c accepts the following command line arguments:

Requirements:

Evaluation

You will receive zero points if you break any of the rules or your code is buggy and crashes the driver. Otherwise, your grade will be calculated as follows:

Hints

Don't worry about reducing the heap size. Watch out that some requests might not be word-aligned. Pre-lab exercise (for slide) If you need more space on the heap, increase it in chunks of 1<<12 bytes

Submission

Before submitting your lab, remove all object (.o) files (for example, with a make clean command). Make a gzipped tarball (.tgz) of the directory with your .c, Makefile and rubric-yourlastname.txt files. Submit your tarball at https://3240.cs.mtsu.edu/. For further instructions, please see the Miscellaneous page.

Rubric:

Points       Item
----------   --------------------------------------------------------------
_____ / 10   Style
_____ / 44   Correctness
_____ / 44   Performance
_____ /  0   Compiles and runs on system64
_____ /  2   Completed rubric (estimates for each line including hours spent)
             
_____ /100   Total


_____  Approximate number of hours spent
      

Notes

  1. Start small. Write your comments first. Then, think through them, adjusting them until you've accounted for all possible situations. Then, add in code and test it a little at a time. For example, write the supporting code for mm_malloc() a piece at a time.
  2. Note: Based off a lab at CMU by the authors of the textbook.