ECE 650编程 写作、 辅导C/C++程序语言

” ECE 650编程 写作、 辅导C/C++程序语言Assignment #1: Malloc Library Part 1ECE 650 Spring 2021See course site for due dateGeneral Instructions1. You will work individually on this the project.2. The code for this assignment should be developed and tested in a UNIX-basedenvironment. You can use the VM that has been made available to you for ECE551.3. You must follow this assignment specs carefully, and turn in everything that is asked(and in the proper formats, as described).4. You should plan to start early on this project and make steady progress over time. It willtake time and careful though to work through the assignment.Implementation of malloc libraryFor this assignment, you will implement your own version of several memory allocationfunctions from the C standard library (actually you will have the chance to implement and studyseveral different versions as described below). Your implementation is to be done in C code.The C standard library includes 4 Malloc-related library functions: malloc(), free(),calloc(), and realloc(). In this assignment, you only need to implement versions ofmalloc() and free():void * malloc(size_t size);void free(void *ptr);Please refer to the man pages for full descriptions of the expected operation for thesefunctions. Essentially, Malloc() takes in a size (number of bytes) for a memory allocation,locates an address in the programs data region where there is enough space to fit the specifiednumber of bytes, and returns this address for use by the calling program. The free() functiontakes an address (that was returned by a previous malloc operation) and marks that dataregion as available again for use.The submission instructions at the end of this assignment description provide specific detailsabout what code files to create, what to name your new versions of the malloc functions, etc.As you work through implementing malloc() and free(), you will discover that as memoryallocations and deallocations happen, you will sometimes free a region of memory that isadjacent to other also free memory region(s). Your implementation is required to coalesce inthis situation by merging the adjacent free regions into a single free region of memory.Hint: For implementing malloc(), you should become familiar with the sbrk() system call.This system call is useful for: 1) returning the address that represents the current end of theprocesses data segment (called program break), and 2) growing the size of the processes datasegment by the amount specified by increment.void *sbrk(intptr_t increment);Hint: A common way to implement malloc() / free() and manage the memory space is tokeep an adequate data structure to Represent a list of free memory regions. This collection offree memory ranges would change as malloc() and free() are called to allocate andrelease regions of memory in the process data segment. You may design and implement yourmalloc and free using structures and state tracking as you see best fit.In this assignment, you will Develop a malloc implementation and study different allocationpolicies.Study of Memory Allocation PoliciesYour task is to implement 2 versions of malloc and free, each based on a different strategyfor determining the memory region to allocate. The two strategies are:1. First Fit: Examine the free space tracker (e.g. free list), and allocate an address fromthe first free region with enough space to fit the requested allocation size.2. Best Fit: Examine all of the free space information, and allocate an address from thefree region which has the smallest number of bytes greater than or equal to therequested allocation size.The following picture illustrates how each strategy would operate (assuming free regions aretraversed in a left to right order) for a malloc() request of 2 bytes:Requirements: Malloc implementationsTo implement your allocation strategies, you will create 4 functions://First Fit malloc/freevoid * ff_malloc(size_t size);void ff_free(void * ptr);//Best Fit malloc/freevoid * bf_malloc(size_t size);void bf_free(void * ptr);Note, that in all cases, a policy to minimize the size of the processs data segment should beused. In other words, if there is no free space that fits an allocation request, then sbrk()should be used to create that space. However, you do not need to perform any type of garbagecollection (e.g. reducing the size of the processs data segment, even if allocations at the top ofthe data segment have been freed).On free(), your implementation is required to merge the newly freed region with any currentlyfree adjacent regions. In other words, your bookkeeping data structure should not containmultiple adjacent free regions, as this would lead to poor region selection during malloc.Requirement: Performance study reportIn addition to implementing these malloc functions, you are tasked to conduct a performancestudy of the malloc()with different allocation policies. Several programs for experimentationwill be provided that perform malloc() and free() requests with different patterns (e.g.frequencies, sizes). The Metrics of interest will be:1) the run-time of the programs, as the implementation of different allocation policies mayresult in different speeds of memory allocation;2) the memory fragmentation is a number in the interval [0,1] (interpreted as apercenbtage), which is measured as follows:1 (size of largest allocatable memory block/total size of free memory)In order to capture #2, you should also implement two additional library functions:unsigned long get_largest_free_data_segment_size();//in bytesunsigned long get_total_free_size();//in bytesThen, using these functions, you can use the included test programs as well as test programs ofyour own creation to evaluate and compare the algorithms.The Starter KitA starter kit is included in a File on Sakai: homework1-kit.tgzThis archive can be extracted using tar xvzf homework1-kit.tgz.The kit includes: Makefile: A sample Makefile for libmymalloc.so. general_tests/: General correctness test, see README.txt for details. alloc_policy_tests/: Allocation policy test cases, see README.txt for details. alloc_policy_tests_osx/: Same thing adapted for MacOS.NOTE: Mac OS is not the grading platform; these files are provided as a convenience.Additionally, you may need to change #include time.h to #include sys/time.hTesting your systemCode is provided for minimal testing, but the provided materials will not exhaustively evaluatethe correctness of your implementation. It is recommended to create your own test software thatuses your library, both to aid during development and to ensure correctness in a variety ofsituations.Detailed Submission Instructions1. Please submit a written report called report.pdf to Sakai (a submission link will beposted soon). The report should include an overview of how you implemented theallocation policies, results from your performance experiments, and an analysis of theresults (e.g. why do you believe you observed the results that you did for differentpolicies with different malloc/free patterns, do you have recommendations for whichpolicy seems most effective, etc.).2. Please submit a Zipped file hw1_netID.zip to Sakai (e.g., if the netID is abc123, thename of the file should be hw1_abc123.zip). All source code should be included in adirectory named my_malloc. There should be a header file name my_malloc.h with the function definitionsfor all *_malloc() and *_free() functions. You may implement these functions in my_malloc.c. If you would like to usedifferent C source files, please describe what those are in the report. There should be a Makefile which contains at least two targets: 1) all shouldbuild your code into a shared library named libmymalloc.so, and 2) cleanshould remove all files except for the source code files. The provided Makefilemay be used as-is, expanded upon, or replaced entirely. If you have notcompiled code into a shared library before, you should be able to find plenty ofinformation online. With this Makefile infrastructure, the test programs will beable to: 1) #include my_malloc.h and 2) link against libmymalloc.so (-lmymalloc), and then Have access to the new malloc functions. Just like that, youwill have created your own version of the malloc routines in the C standardlibrary!如有需要,请加QQ:99515681 或WX:codehelp

添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导