PA2 - Programming Assignment#2 Memory Allocation Package...

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

View Full Document Right Arrow Icon
Programming Assignment #2: Memory Allocation Package) Due: see My Courses for the deadline What is required as part of this assignment? In this assignment, you will develop a memory allocation library that is equivalent to the malloc library provided by Unix-like operating systems. The malloc() function allocates variable sized contiguous memory chunks on the heap, which is the memory segment just after the uninitialized data segment. The current end of the heap is given by the program break as shown in the figure below. The malloc() and related functions are built on top of brk() and sbrk() , which we discuss next. To allocate memory on the heap, we need to tell the kernel that the process’ program break is located at a different address such that there is additional room in the heap. Initially, the program break lies just past the end of the uninitialized data segment. After the program break is increased, the program can access the memory in the newly created heap space. The brk() system call sets the program break to the location specified by its argument. The sbrk() library routine is similar where an increment can be specified to increase the program break.
Image of page 1

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

View Full Document Right Arrow Icon
The call sbrk(0) returns the current value of the program break without changing it. It can be useful to track the size of the heap to monitor the behavior of the memory allocation package. Your memory allocation package needs to provide the following functions for managing the heap. void *my_malloc(int size) This function returns void pointer that we can assign to any C pointer. If memory could not be allocated, then my_malloc() returns NULL and sets a global error string variable given by the following declaration.
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