



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Important: This project may be done individually or in pairs. Be sure to carefully read the course policies for assignments (including the honor code policy) on the assignments page of the course web site:
http://www.owlnet.rice.edu/˜comp221/2008/html/assignments.html
In this lab you will be writing a dynamic memory allocator for C programs, i.e., your own version of the malloc, free and realloc routines. You are encouraged to explore the design space creatively and implement an allocator that is correct, efficient and fast.
Your dynamic memory 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 we have given you implements a simple, but still functionally correct, malloc package. 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 the semantics of the corresponding libc malloc, realloc, and free routines. Type man malloc for complete documentation.
Heap Consistency Checker
Dynamic memory allocators are notoriously tricky 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:
Programming Rules
Hints
Evaluation
To turn in your code, you should run the ˜comp221/bin/proj5submit program in the directory that contains the files you wish to submit. Be sure that your code and writeup are contained in files named mm.c, and writeup.txt. Note that we will only use your mm.c along with the original files that were handed out to test your code, so you should not add or modify code in any other file (except during testing, as necessary). Note that the proj5submit program submits your entire directory. If there are additional files in the directory, that is okay, but we will not use them for grading purposes. The project will be graded as follows: You will receive zero points for correctness and performance if you break any of the programming rules or your code is buggy and crashes the driver. Otherwise, your grade will be calculated as follows:
The driver program summarizes the performance of your allocator by computing a performance index , P , which is a weighted sum of the space utilization and throughput
P = wU + (1 − w) min
( 1 ,
Tlibc
)
where U is your space utilization, T is your throughput, and Tlibc is the estimated throughput of libc malloc on your system on the default traces.^1 The performance index favors space utilization over throughput, with a default of w = 0. 6. Observing that both memory and CPU cycles are expensive system resources, we adopt this formula to encourage balanced optimization of both memory utilization and throughput. Ideally, the performance (^1) The value for Tlibc is a constant in the driver (3400 Kops/s) that is based on the libc allocator performance on long-eared.