[Solved] CS0449 Project 2- Memory Allocator

$25

File Name: CS0449_Project_2__Memory_Allocator.zip
File Size: 320.28 KB

SKU: [Solved] CS0449 Project 2- Memory Allocator Category: Tag:
5/5 - (1 vote)

In this project, you will be implementing a memory allocator. Youll be making your own versions of the malloc and free functions! Yay! Fun!

Materials

You are given the following source files to begin with. Right click and download these files. Read the comments inside them thoroughly before getting started.

mymalloc.c is where youll be writing all your code for this project.

The mydriver.c file contains a main function for you to expand upon. By default it just allocates and frees a single block of memory. As you work on your allocator, you can add more testing code to this driver program to make sure it works.

Makefile is a makefile to make your driver, and eventually, other test file(s) that I give you.

The bigdriver.c file is a driver I made to test your allocator more thoroughly. READ THE COMMENTS INSIDE IT THOROUGHLY TO HELP DEBUG ANY ISSUES THAT COME UP.

Although bigdriver.c does a lot of tests, it might not catch all bugs. Look at it closely and add tests if you think its not thorough enough. You can change it and submit it along with your mydriver.c.

Building and running

To build everything, use the following command line:

make mydriver

Ignoring warnings in this project would be a very, very bad idea. The Makefile uses -Wall -Werror. Do not remove these. Fix all the warnings. SERIOUSLY.

Then, you should be able to:

./mydriver

You can do the same with bigdriver:

make bigdriver./bigdriver

Your Task

You will write my_malloc and my_free which implement a simple memory allocator using a linked list and a first-fit allocation scheme. The performance wont be great, but hey, its a class project, not a AAA game engine.

Your my_malloc function will:

  • Round up the size of the requested allocation to a certain size (I gave you this)
  • Try to find a block to reuse, using first-fit allocation
  • If it found a block, and that block can be split into two smaller blocks, do so
  • If it couldnt find a block, expand the heap by moving the break with sbrk()
  • Mark it as used
  • Return the pointer to the data part (after the header)

Your my_free function will:

  • Figure out the pointer to the header
  • Mark the block free
  • Coalesce it with any neighboring blocks on either side
  • If its the last block on the heap, contract the heap by moving the break with sbrk()

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS0449 Project 2- Memory Allocator[Solved] CS0449 Project 2- Memory Allocator
$25