Assignment 4: Malloc: Writing a Dynamic Storage Allocator
Assigned: Tuesday, October 4
Design Checkpoint Deadline: Thursday, October 13, 10:00PM
Assignment due: Thursday, October 20, 11:59PM
1
Introduction
In this assignment you will write a dynamic storage allocator for C programs, that is, 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.
Please read this document in its entirety. It contains important information about the assignment and how you will be assessed, and provides hints for you to succeed at this assignment.
Any clarifications or revisions to this assignment will be posted on the course website.
2
Getting started
You can do this homework in groups of one or two students. Please go to the form at http://tinyurl.com/CS61-Fa11-malloc-groups and let us know your group. (This form is also linked to from the CS 61 web page.)
Please fill out the form even if you are working on this assignment by yourself —simply leave the
“Partner 2” fields blank.
Please fill in this form by 11:59pm, Sunday October 9.
In your home directory on your CS 61 VM, you should have a directory called malloc. Please contact course staff if you do not have this directory. The directory malloc contains several files.
The only file that you will modify and submit is the file mm.c.
The file mm.c contains a C structure team. Please edit this structure to add identifying information about your group. Do this right away so you don’t forget.
1
3
Implementing your dynamic storage allocator
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 we have given you implements the simplest but still