C/C++ 编程代写
当前位置:以往案例 > >CS案例:C语言案例内存分布器代码案例编程
2018-09-03



1 Introduction

In this programming project 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 most importantly correct. It should also be memory efficient and fast.



2 Logistics

Since this project is quite large, I will allow you to work in team. However, if you choose to work alone, you can do so for a 10% bonus. (I will add 10% to the total points you’ve earned.) If you want to work in a large team with more than two members, you can do so for a 10% penalty. (I will detect 10% from the total points your team has earned.) You will have a choice of building two systems. One will have the limit of 3 members per team and the other will have the limit of 4 members per team. Any clarifications and revisions to the project will be posted on canvas.



3 Hand Out Instructions

Start by downloading malloc-project.zip to a protected directory in CSCE.UNL.EDU (Note that the system is CSCE and not CSE.). Then issue the command: unzip malloc-project.zip. This will cause a number of files to be unpacked into the directory called malloc-project. The only file you will be modifying and handing in is mm.c. The mdriver.c program is a driver program that allows you to evaluate the correctness and 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 infor- mation.) ./mdriver -lV also reports the performance of the dynamic memory management routines from standard C library (glibc).

Looking at the file mm.c you’ll notice a C structure team into which you should insert the requested identifying information about your team. Do this right away so you don’t forget.







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


4 How to Work on the 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 we are providing, implements a simple implicit list with no boundary tags. As such, traversing the list can only be done in one direction. We only implement mm init and mm malloc. The latter is working but poorly utilizing memory and operating slowly. Thus, when we use it with the provided memory allocation traces, it can only pass 6 of the 11 tests. It fails 3 tests due to out-of-memory and 2 tests due to lack of support for mm realloc.

Using this as a starting place, implement mm free and mm realloc. The semantic of each function is described below.


• mm init: Before calling mm malloc mm realloc or mm free, the application program (i.e., the trace-driven driver program that you will use to evaluate your implementation) calls mm init to perform any necessary initializations, such as allocating the initial heap area. The return value should be -1 if there was a problem in performing the initialization, the staring address of the heap otherwise.

• mm malloc: The mm malloc routine returns a pointer to an allocated block payload of at least size bytes. The entire allocated block should lie within the heap region and should not overlap with any other allocated chunk.

We will compare your implementation to the version of malloc supplied in the standard C library (glibc). Since the glibc malloc always returns payload pointers that are aligned to 8 bytes, your malloc implementation should do likewise and always return 8-byte aligned pointers. Our mdriver program tests for 8-byte alignment and terminates if the alignment check fails.


• mm free: The mm free routine frees the block pointed to by ptr. It returns nothing. This routine is only guaranteed to work correctly when the passed pointer (ptr) was returned by an earlier call to mm malloc or mm realloc and has not yet been freed.

• mm

在线提交订单