preview

Malloc Lab: Writing a Dynamic Storage Allocator

Better Essays

Fall 2008 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: December 16, Due: December 28, 11:59PM
YanQiben 12.16 2008

YanQiben (072021029@fudan.edu.cn) is the lead person for this assignment.

1 Introduction
In this lab you will be writing a dynamic storage 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.

2 Logistics
You may work in a group of up to one people. Any clarifications and revisions to the assignment will be posted on the course Web page.

3 Hand Out Instructions
Start by copying malloclab-handout.tar to a protected directory in which you plan to do your …show more content…

Similarly, if the old block is 8 bytes and the new block is 4 bytes, then the contents of the new block are identical to the first 4 bytes of the old block. These semantics match the the semantics of the corresponding libc malloc, realloc, and free routines. Type man malloc to the shell for complete documentation.

5 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: • Is every block in the free list marked as free? • Are there any contiguous free blocks that somehow escaped coalescing? • Is every free block actually in the free list? • Do the pointers in the free list point to valid free blocks? • Do any allocated blocks overlap? • Do the pointers in a heap block point to valid heap addresses? 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

Get Access