On this page:
Getting Started
How to Work on the Lab
Driver Program
Programming Rules
Evaluation
Tips

Malloc Assignment

This malloc assignment is based on the one by Bryant and O’Hallaron for Computer Systems: A Programmer’s Perspective, Third Edition

Due: Wednesday, November 21, 11:59pm

In this lab, you’ll write a dynamic storage allocator for C programs, i.e., your own version of the malloc and free functions. Specifically, your library will provide mm_malloc and mm_free analogous to malloc and free.

Getting Started

Start by unpacking malloclab-handout.zip. The only file you will be modifying and handing in is "mm.c". The "usemem.c" program is a driver program that allows you to test and evaluate your solution, where a command-line flag selects a test mode. Use make to generate the driver code and run it as, for example,

  $ ./usemem --single

See Driver Program for information about command-line flags to usemem.

When you have completed the lab, you will hand in only one file, "mm.c", which contains your solution.

How to Work on the Lab

Your dynamic storage allocator will consist of the following three functions, which are declared in "mm.h" and defined in "mm.c":

  int   mm_init(void *heap, size_t heap_size);

  void *mm_malloc(size_t size);

  void  mm_free(void *ptr);

The "mm.c" file that we have given you implements a very simple allocator that handles a single allocation block. It passes only the --single testing mode of usemem. You will need to improve the allocator to pass other modes.

Beyond correctness, your goal is to produce an allocator that performs well in time and space. That is, the mm_malloc and mm_free functions should should stay close enough to the amount of memory needed to hold the payload of mm_malloc calls, and it should work quickly enough. The higher levels of completion correspond to lower overhead and higher performance.

Driver Program

The usemem program calls mm_init, mm_malloc, and mm_free in different patterns to exercise your allocator in different, increasingly demanding ways, parameterzied by a count n, size s, and iteration count iters.

Independent of the mode, usemem also accepts the following flags:

Programming Rules
Evaluation

Your grade will be calculated as follows:

The makefile provides test60, test80, test90, and test100 targets that run tests for all modes for the corresponding grade. The tests include varying n and s values, and all combinations must pass. Running all tests should take under 1 second.

Tips