Question: Implement a version of HeapManager with a best - fit mechanism. Start with a renamed copy of the HeapManager class, and then modify the allocate
Implement a version of HeapManager with a bestfit mechanism. Start with a renamed copy of the HeapManager class, and then modify the allocate method to implement a bestfit search. The code for HeapManager is available on the Web site for this book. It includes the coalescing version of dealocate, which is the one you should use.
After this has been tested and works, find a simple sequence of operations for which your bestfit manager succeeds while the firstfit one fails. Hint: There is a sequence that begins like this:
new HeapManager new int ;
int allocate ;
int allocate ;
int allocate ;
mm deallocate ;
mm deallocate c ;
By extending this sequence with just two more calls to mu allocate, you can get something that will succeed for bestfit and fail for firstfit.
Although bestfit is often a better placement strategy than firstfit, there are examples for which it is worse. Find a simple sequence of operations for which the firstfit manager succeeds while your bestfit one fails. Hint: There is a sequence that begins like this:
mim new HeapManager new int ;
allocate ;
b allocate ;
allocate ;
mm deallocate ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
