代做program、代写c/c++编程设计
159.342 - Operating Systems and Networks
Assignment #3 (due on 6/Jun)
Memory Management Using the Buddy System Strategy
OBJECTIVE:
The main objective in this assignment is to implement the Buddy System memory management
strategy by writing two functions that implement the same functionalities as the C Standard library’s
malloc() and free(). You should apply your knowledge of memory management concepts, so the
functions are as efficient as possible. The buddy system will be characterised and compared against
the existing C Standard library functions based on ACTUAL RUNNING TIME and MEMORY USAGE.
Given a large block of contiguous memory to manage, your functions should be able to fulfil a series
of memory allocation and deallocation requests. In your implementation, you are not allowed to
use the built-in malloc, free, new, delete or any other memory allocators that come from other
third-party libraries.
START-UP CODES:
The start-up codes provide a test routine that makes successive calls for memory allocations and
deallocations, involving a replaceable implementation of MALLOC and FREE. Functions for
measuring the actual running time and total memory usage of the memory management strategy
are also provided.
///////////////////////////////
// TEST ROUTINE
///////////////////////////////
#ifdef RUN_COMPLETE_TEST
cout << "\n\n executing " << NO_OF_ITERATIONS << " rounds of combinations of memory allocation and deallocation..." <<
endl;

for(i=0;i k=myrand() % NO_OF_POINTERS; // pick a pointer
if(n[k]) { // if it was allocated then free it
// check that the stuff we wrote has not changed
if ( (n[k][0]) != (unsigned char) k)//(n[k]+s[k]+k) )
printf("Error when checking first byte! in block %d \n",k);
if(s[k]>1 && (n[k][s[k]-1])!=(unsigned char) k )//(n[k]-s[k]-k))
printf("Error when checking last byte! in block %d \n",k);
FREE(n[k]);
}
size=randomsize(); // pick a random size
#ifdef DEBUG_MODE
cout << "\tPick random size to allocate: " << size << endl;
#endif

n[k]=(unsigned char *)MALLOC(size); // do the allocation
if(n[k] != NULL){
#ifdef DEBUG_MODE
cout << "\tallocated memory of size: " << size << endl;
#endif
s[k]=size; // remember the size
n[k][0]=(unsigned char) k; // put some data in the first and
if(s[k]>1) n[k][s[k]-1]=(unsigned char) k; // last byte
} else {
cout << "\tFailed to allocate memory of size: " << size << endl;
}
}
#endif
n.h.reyes@massey.ac.nz
Selecting a memory management strategy to test
You can switch between different memory management strategies by changing the definition of
MALLOC and FREE, as defined inside main.cpp (see below). The first two options are already
provided, but the third option corresponds to the Buddy System and therefore, needs to be
implemented in this assignment:
//---------------------------------------
// WHICH MEMORY MANAGEMENT STRATEGY?
//---------------------------------------
// enable the following compiler directives to test the real malloc and free
//(1) use built-in C functions
const string strategy = "malloc";
#define MALLOC malloc
#define FREE free
//---------------------------------------
//enable the following compiler directives to test a simple implementation of malloc and free
//(2) use user-defined functions
//const string strategy = "mymalloc";
// #define MALLOC mymalloc
// #define FREE myfree
//---------------------------------------
//enable the following compiler directives to test your implementation of the Buddy system strategy
//(3) use Buddy System
// const string strategy = "Buddy System";
// #define USE_BUDDY_SYSTEM
// #define MALLOC buddyMalloc
// #define FREE buddyFree
//---------------------------------------
CORE FUNCTIONS REQUIRED:
Skeleton functions for buddy system’s malloc and free are already provided inside buddysys.cpp.
Write your implementation inside them. You are allowed to add any supporting functions, data
structures and variables in the program.
void *buddyMalloc(int request_memory){
//write your buddy system’s memory allocation codes here
//this function should provide the same functionality as the malloc() function
}
int buddyFree(void *p){
//write your buddy system’s memory deallocation codes here
//this function should provide the same functionality as the free() function
}
AUXILIARY FUNCTIONS PROVIDED:
The Auxiliary functions, constants and data structures declared and implemented inside auxiliary.cpp
and auxiliary.h should all be kept as is.
MINIMUM CONTIGUOUS MEMORY SIZE
As part of characterising the performance of your implementation, find the minimum contiguous
memory size that allows the Buddy System strategy to accommodate the succession of memory
allocation and deallocation requests in the test routine. To accomplish this, you need to experiment
with different settings for the NUMBEROFPAGES until the test routine could be fully completed.
Example:
As an example, if you set NUMBEROFPAGES equal to 1024, then the MEMORYSIZE could be
computed as follows:
// inside main.cpp
MEMORYSIZE = (long long int) ((long long int)NUMBEROFPAGES * (long long int)PAGESIZE);
Note that in the start-up codes, the PAGESIZE is set to 4096. Therefore, MEMORYSIZE will be equal
to 4,194,304 bytes (1024 * 4096) or 4.19 MegaBytes.
Next, with your MEMORYSIZE setting, run the test routines to see if all requests for memory
allocations and deallocations can be satisfied.
If the test routine cannot be completed, repeat the following steps until the test routine can be
completed.
1. increase the MEMORYSIZE by a small amount, then recompile the code
2. run the test routine.
MEASURE OF PERFORMANCE
Download the Excel file, named assignment_documentation.xlsx from our stream website.
Characterise your Buddy System implementation and compare it against the C Standard library’s
malloc and free to see if its speed of execution is comparable. Fill-up the Excel worksheet to
document your experiment results. You only need to record the performance of your Buddy System
implementation.
DEBUGGING:
For debugging purposes, I have created a simple test routine (inside the start-up codes) to assist the
class. To activate this simple test temporarily, modify the auxillary.h file to enable
RUN_SIMPLE_TEST as follows:
Before submitting your assignment, you should comment out #define RUN_SIMPLE_TEST and re activate #define RUN_COMPLETE_TEST again.
n.h.reyes@massey.ac.nz
n.h.reyes@massey.ac.nz
Further, inside main.cpp, I have made a provision for this Simple Test already, it will automatically
switch to using 512 bytes as the MEMORYSIZE, to conduct the test.
For more details on how to debug your codes, please see the file, named
A3_debugging_tips_2025_v1.docx. This is downloadable from our stream website.
SUBMISSION INSTRUCTIONS:
1. Submit your complete C/C++ program electronically via Stream.
2. Use the following filename for your main program (as set in the start-up codes): main.cpp
3. Submit the makefile for building your codes. The makefile should suffice to build your
codes.
4. As a backup, if you developed your program using an IDE, such as VSCODE or Clion, also
submit the complete support files (e.g. CMakeLists.txt, project file, *.sln, *.JSON, etc.), for
building your codes.
5. Assignment documentation file: Download and fill out the Excel file, named
assignment_documentation.xlsx to provide important information about your work.
Rename the file using your ID_number (e.g. 87654321.xlsx). This will help facilitate
accurate marking of your assignment. Deductions will be made if you do not submit the
completed Excel file.
6. Snapshots file: Create a document containing snapshots of the simulation results. Show the
results of executing RUN_COMPLETE_TEST. If this cannot be achieved, for partial marks, show
the results of executing RUN_SIMPLE_TEST.
Label and briefly describe each image. You may create a Word document or a pdf file to
accomplish this task.
7. Create a zip file containing the following files:
o Complete set of codes (including *.cpp, *.h, makefile, other supporting files)
o Snapshots file
8. Submit the zip file containing your complete program and snapshots electronically via
Stream. You will find a button with the following label.
9. Submit the assignment documentation Excel file via Stream website. You will find a
separate button with the following label.
10. Lastly, submit the Gen AI Usage documentation file via Stream website. You will find a
separate button with the following label.
Distribution of marks:
The assignment will be marked based on functionality, design and correctness.
The marks are distributed as follows:
• 5 marks: for correct implementation of buddyMalloc.
• 5 marks: for correct implementation of buddyFree.
• 3 marks: for memory efficiency (Note: this is based on the minimum contiguous memory
size that allows the Buddy System strategy to accommodate the succession of memory
allocation and deallocation requests in the RUN_COMPLETE_TEST routine)
• 2 marks: for documentation (i.e. accurate documentation of performance and other
important assignment details - Excel assignment documentation, snapshots).
Other Notes
• This assignment is worth 15 marks.
• Marks will be subtracted for obvious copying and/or for delays without justification.

热门主题

课程名

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
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图