首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
代写CS 551、代做C/C++编程语言
项目预算:
开发周期:
发布时间:
要求地区:
CS 551 Systems Programming, Fall 2024
Programming Project 1 Out: 10/13/2024 Sun.
Due: 10/26/2024 Sat. 23:59:59
In this project your are going to implement a custom memory manager that manages heap memory allocation at program level. Here are the reasons why we need a custom memory manager in C.
• The C memory allocation functions malloc and free bring performance overhead: these calls may lead to a switch between user-space and kernel-space. For programs that do fre- quent memory allocation/deallocation, using malloc/free will degrade the performance.
• A custom memory manager allows for detection of memory misuses, such as memory over- flow, memory leak and double deallocating a pointer.
The goal of this project is to allow students to practice on C programming, especially on bitwise operations, pointer operation, linked list, and memory management.
Figure 1: Overview
1 Overview
Figure 1 depicts where the memory manager locates in a system. The memory manager basically preallocates chunks of memory, and performs management on them based on the user program memory allocation/deallocation requests.
We use an example to illustrate how your memory manager is supposed to work. Suppose memory allocations in the memory manager are 16 bytes aligned1.
• After the user program starts, the first memory allocation from the program requests 12 bytes of memory (malloc(12)). Prior to this first request, your memory manager is initialized
1In other words, the memory manager always allocates memory that is a multiple of 16 bytes. In the base code, this is controlled by the MEM ALIGNMENT BOUNDARY macro defined in memory manager.h
User program
User program
malloc/free
malloc/free (interposed version)
malloc/free
OS kernel
Your memory manager (a library)
OS kernel
with a batch of memory slots2, each of which has a size of 16 bytes. Memory manager returns the first slot of the batch to the user program.
• Then the user program makes a second request (malloc(10)). Because the memory al- location is 16 bytes aligned, the memory manager should return a chunk of memory of 16 bytes. This time, because there are still available 16-byte-slots in the allocated batch, the memory manager simply return the second slot in the allocated batch to fulfill the request without interacting with the kernel.
• The user program makes 6 subsequent memory requests, all of which are for memory less than 16 bytes. The memory manager simply returns each of the rest 6 free 16-byte-slots to fulfill the requests. And for the implementation of this project, assume you will only get requests for less than or equal to 16 bytes memory.
• The user program makes the 9th request (malloc(7)). Because there is no free slots avail- able, the manager allocates another batch of memory slots of 16 bytes, and returns the first slot in this batch to the user program.
• Suppose the 10th memory request from the user program is malloc(28). The manager should return a memory chunk of 32 bytes (remember memory allocation is 16 bytes aligned). Because there is no memory list of 32-byte-slots, the manager has to allocate a batch of memory slots of 32 bytes, and returns the first slot to fulfill this request. At this moment, the memory list of 32-byte-slots has only one memory batch.
• The memory manager organizes memory batches that have the same slot size using linked list, and the resulting list is called a memory batch list, or a memory list.
• Memory lists are also linked together using linked list. So the default memory list with slot size of 16 bytes is linked with the newly created 32 bytes slot size memory list.
• The manager uses a bitmap to track and manage slots allocation/deallocation for each memory batch list.
It is easy to see that with such a mechanism, the memory manager not only improves program performance by reducing the number of kernel/user space switches, but also tracks all the memory allocation/deallocation so that it can detect memory misuse such as double freeing. The memory manager can also add guard bytes at the end of each memory slot to detect memory overflow (just an example, adding guard bytes is not required by this project.)
2 What to do
2.1 Download the base code
Download the base code from Assignments section in the Brightspace. You will need to add your implementation into this base code.
2In the base code, the number of memory slots in a batch is controlled by the MEM BATCH SLOT COUNT macro defined in memory manager.h
2.2 Complete the bitmap operation functions (25 points)
Complete the implementation of the functions in bitmap.c.
• int bitmap find first bit(unsigned char * bitmap, int size, int val)
This function finds the position (starting from 0) of the first bit whose value is “val” in the “bitmap”. The val could be either 0 or 1.
Suppose
unsigned char bitmap[] = {0xF7, 0xFF};
Then a call as following
bitmap_find_first_bit(bitmap, sizeof(bitmap), 0);
finds the first bit whose value is 0. The return value should be 3 in this case.
• int bitmap set bit(unsigned char * bitmap, int size, int target pos)
This function sets the “target pos”-th bit (starting from 0) in the “bitmap” to 1.
Suppose
unsigned char bitmap[] = {0xF7, 0xFF};
Then a call as following
bitmap_set_bit(bitmap, sizeof(bitmap), 3);
sets bit-3 to 1. After the call the content of the bitmap is {0xFF, 0xFF};
• int bitmap clear bit(unsigned char * bitmap, int size, int target pos)
This function sets the “target pos”-th bit (starting from 0) in the “bitmap” to 0.
• int bitmap bit is set(unsigned char * bitmap, int size, int pos)
This function tests if the “pos”-th bit (starting from 0) in the “bitmap” is 1.
Suppose
unsigned char bitmap[] = {0xF7, 0xFF};
Then a call as following
bitmap_bit_is_set(bitmap, sizeof(bitmap), 3);
returns 0, because the bit-3 in the bitmap is 0.
• int bitmap print bitmap(unsigned char * bitmap, int size)
This function prints the content of a bitmap in starting from the first bit, and insert a space
every 4 bits. Suppose
unsigned char bitmap[] = {0xA7, 0xB5};
Then a call to the function would print the content of the bitmap as
1110 0101 1010 1101
The implementation of this function is given.
2.3 Complete the memory manager implementation (70 points)
In memory manager.h two important structures are defined:
• struct stru mem batch: structure definition of the a memory batch (of memory slots). • struct stru mem list: structure definition of a memory list (of memory batches).
To better assist you understand how a memory manager is supposed to organize the memory using the two data structures, Figure 2 shows an example of a possible snapshot of the memory manager’s data structures.
Figure 2: An example of data structures Basically there are two kinds of linked list:
• A list of memory batches (with a certain slot size): as shown in the previous example, this list expands when there is no free slot available. The memory manager adds a new batch at the end of the list.
• A list of memory batch list: this list expands when a new slot size comes in. You will need to implement the functions in memory manager.c:
• void * mem mngr alloc(size t size)
– This is the memory allocation function of the memory manager. It is used in the same way as malloc().
– Provide your implementation.
– The macro MEM ALIGNMENT BOUNDARY (defined in memory manager.h) controls how memory allocation is aligned. For this project, we use 16 byte aligned. But your implementation should be able to handle any alignment. One reason to de- fine the alignment as a macro is to allow for easy configuration. When grading we will test alignment that is multiples of 16 by changing the definition of the macro MEM ALIGNMENT BOUNDARY to 8, 32, ....
– The macro MEM BATCH SLOT COUNT (defined in memory manager.h) controls the number of slots in a memory batch. For this project this number is set to 8. But your implementation should also work if we change to the macro MEM BATCH SLOT COUNT to other values. When grading, we will test the cases when MEM BATCH SLOT COUNT is set to multiples of 8 (i.e., 8, 16, 24, ...).
– When there are multiple free slots, return the slot using the first-fit policy(i.e, the one with smallest address).
– Remember to clear the corresponding bit in free slots bitmap after a slot is allo- cated to user program.
– Do not use array for bitmap, because you never now how many bits you will need. Use heap memory instead.
– Remember to expand the bitmap when a new batch is added to a list, and keep the old content after expansion.
– Create a new memory list to handle the request if none of the existing memory list can deal with the requested size.
– Add this memory list into the list of memory lists.
– This function should support allocation size up to 5 times the alignment size, e.g., 80
bytes for 16 byte alignment.
• void mem mngr free(void * ptr)
– This is the memory free function of the memory manager. It is used in the same way
as free().
– Provide your implementation.
– The ptr should be a starting address of an assigned slot, report(print out) error if it is not (three possible cases:
1: ptr is the starting address of an unassigned slot - double freeing;
2: ptr is outside of memory managed by the manager;
3: ptr is not the starting address of any slot).
– Remeber to set the corresponding bit in free slots bitmap after a slot is freed, so
that it can be used again.
– Search through all the memory lists to find out which memory batch the ptr associated slot belongs to.
2.4
•
void mem mngr init(void)
– This function is called by user program when it starts.
– Initialize the lists of memory batch list with one default batch list. The slot size of this default batch list is 16 bytes.
– Initialize this default list with one batch of memory slots.
– Initialize the bitmap of this default list with all bits set to 1, which suggests that all
slots in the batch are free to be allocated.
void mem mngr leave(void)
– This function is called by user program when it quits. It basically frees all the heap
memory allocated.
– Provide your implementation.
– Don’t forget to free all the memory lists to avoid memory leak.
void mem mngr print snapshot(void)
This function has already been implemented. It prints out the current status of the memory manager. Reading this function may help you understand how the memory manager orga- nizes the memory. Do not change the implementation of this function. It will be used to help the grading.
Writing a makefile (5 points)
•
•
Write a makefile to generate
• • •
2.5
Log your work: besides the files needed to build your project, you must also include a README
file which minimally contains your name and B-number. Additionally, it can contain the following:
• The status of your program (especially, if not fully complete).
• Bonus is implemented or not.
• A description of how your code works, if that is not completely clear by reading the code (note that this should not be necessary, ideally your code should be self-documenting).
• Possibly a log of test cases which work and which don’t work.
• Any other material you believe is relevant to the grading of your project.
memory manager.o bitmap.o
a static library memory manager.a, which contains the previous relocatable object files. This library will be linked to our test program for testing.
Log and submit your work
Compress the files: compress the following into a ZIP file: • bitmap.c
• common.h
• interposition.h
• memory manager.c • memory manager.h • Makefile
• README
Name the ZIP file based on your BU email ID. For example, if your BU email is “abc@binghamton.edu”, then the zip file should be “proj1 abc.zip”.
Submission: submit the ZIP file to Brightspace before the deadline. 2.6 Grading guidelines
(1) Prepare the ZIP file on a Linux machine. If your zip file cannot be uncompressed, 5 points off.
(2) If the submitted ZIP file/source code files included in the ZIP file are not named as specified above (so that it causes problems for TA’s automated grading scripts), 10 points off.
(3) If the submitted code does not compile:
1 2 3 4 5 6 7 8 9
TA will try to fix the problem (for no more than 3 minutes);
if (problem solved)
1%-10% points off (based on how complex the fix is, TA’s discretion);
else
TA may contact the student by email or schedule a demo to fix the problem;
if (problem solved)
11%-20% points off (based on how complex the fix is, TA’s discretion);
else
All points off;
So in the case that TA contacts you to fix a problem, please respond to TA’s email promptly or show up at the demo appointment on time; otherwise the line 9 above will be effective.
(4) If the code is not working as required in this spec, the TA should take points based on the assigned full points of the task and the actual problem.
(5) Late penalty: Day1 10%, Day2 20%, Day3 40%, Day4 60%, Day5 80%
(6) Lastly but not the least, stick to the collaboration policy stated in the syllabus: you may discuss with your fellow students, but code should absolutely be kept private. Any violation to the Academic Honesty Policy and University Academic Policy, will result 0 for the work.
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!