{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lab4 - SS10 2011 Lab Assignment 4 Dynamic Memory Allocator...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
SS10, 2011 Lab Assignment 4: Dynamic Memory Allocator Assigned: June 3 Due: June 20, 19:59:59 PM 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. Logistics You should finish this lab by yourself. How to Work on the Lab Your dynamic storage allocator will consist of the following four functions ( mm_init , mm_malloc , mm_free and mm_realloc ), which are declared in mm.h” and defined in “ mm.c” . The “ mm.c” file we have given you implements the simplest but still functionally correct malloc package that we could think of. Using this as a starting point, modify these functions (and possibly define other private static functions), so that they obey the following semantics: 1. mm_init : Before calling mm_malloc mm_realloc or mm_free , the application program (i.e., the trace-driven test harness that you will use to evaluate your implementation) calls mm_init to perform any
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
necessary initializations, such as allocating the initial heap area. The return value should be -1 if there was a problem in performing the initialization, 0 otherwise. 2. 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 (libc). Since the libc malloc always returns payload pointers that are aligned to 8 bytes, your malloc implementation should do likewise and always return 8-byte aligned pointers. 3. mm_free : The mm_free routine frees the block pointed to by ptr . It returns nothing. This routine is only guaranteed to work when the passed pointer ( ptr ) was returned by an earlier call to mm_malloc or mm_realloc and has not yet been freed. 4. mm_realloc : The mm_realloc routine returns a pointer to an allocated region of at least size bytes with the following constraints. o if ptr is NULL, the call is equivalent to mm_malloc ( size ); o if size is equal to zero, the call is equivalent to mm_free ( pt r); o if ptr is not NULL, it must have been returned by an earlier call to mm_malloc or mm_realloc . The call to mm_realloc changes the size of the memory block pointed to by ptr (the old block) to size bytes and returns the address of the new block. Notice that the address of the new block might be the same as the old block, or it might be different, depending on your implementation, the amount of
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern