联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2019-04-14 09:37

Programming Assignment 4: Heap Management

Description

In this assignment you will build your own implementation of malloc and free. That is, you will

need to implement a library that interacts with the operating system to perform heap management

on behalf of a user process as demonstrated in class.

The code you submit for this assignment will be verified against a database consisting of kernel

source, github code, stackoverflow, previous student’s submissions and other internet resources.

Code that is not 100% your own code will result in a grade of 0 and referral to the Office of

Student Conduct.

This project must be completed, in C, on omega.uta.edu. Windows does not support the

sbrk() system call and MacOS/OSX’s implementation of shared libraries is unconventional.

Getting the Source

The source code for this assignment may be found at: https://github.com/CSE3320/Heap-Assignment

Building and Running the Code

The code compiles into four shared libraries and four test programs. To build the code, change to your top level assignment directory and type:

make

Once you have the library, you can use it to override the existing malloc by using

LD_PRELOAD:


$ env LD_PRELOAD=lib/libmalloc-ff.so cat README.md

or

$ env LD_PRELOAD=lib/libmalloc-ff.so tests/test1

To run the other heap management schemes replace libmalloc-ff.so with the appropriate

library:

Best-Fit: libmalloc-bf.so

First-Fit: libmalloc-ff.so

Next-Fit: libmalloc-nf.so

Worst-Fit: libmalloc-wf.so

Program Requirements

Using the framework of malloc and free provided on the course github repository:

1. Implement splitting and coalescing of free blocks. If two free blocks are adjacent then

combine them. If a free block is larger than the requested size then split the block into two.

2. Implement three additional heap management strategies: Next Fit, Worst Fit, Best Fit (First Fit has already been implemented for you).

3. Counters exist in the code for tracking of the following events:

Number of times the user calls malloc successfully

Number of times the user calls free successfully

Number of times we reuse an existing block

Number of times we request a new block

Number of times we split a block

Number of times we coalesce blocks

Number blocks in free list

Total amount of memory requested

Maximum size of the heap

The code will print these statistics upon exit and should look like this:

mallocs: 8

frees: 8

reuses: 1

grows: 5

splits: 1

coalesces: 1

blocks: 5

requested: 7298

max heap: 4096

You will need to increment these counters where appropriate.

4. Four test programs are provided to help debug your code. They are located in the tests directory.

5. Implement realloc and calloc:

void *calloc(size_t nmemb, size_t size);

void *realloc(void *ptr, size_t size);

How to submit homework

1. Submit a gzipped tarball of your source code to blackboard.

Grading

The assignment will be graded out of 100 points. Compiler warnings are there to tell you

something is not correct. Pay attention to them and you will save yourself a lot of late nights

debugging code. Code that does not compile will earn 0.

Your code will be compiled with the provided makefile on omega.uta.edu .


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp