Commit 1a2af07e authored by Lindsay Knupp's avatar Lindsay Knupp
Browse files

Lab 8.3 completed

parent 070277c1
......@@ -17,7 +17,8 @@ double average_frag();
average = 1 - largestblock / total freemem counter
(2.1)
If you make enough allocation/deallocation requests, then the given algorithm
is sufficient to generate enough fragmentation. If you were to make 20 requests,then the beginning of the free list would be allocated, put back, and then the next request would be allocated from the new "beginning" of the free list since the leftover block would still be sufficiently big to house the next allocation request.
If you make enough allocation/deallocation requests, then the given algorithm is mostly correct. You just need to add an extra if statement that checks if that space was actually allocated or not. If not then you can't try to deallocate it.
You are essentially just chopping up the free list into a bunch of small blocks so this algorithm will work.
I used the pseudo-code given to me in the lab.
(3.2) For my simulation of allocating and deallocating, best fit results in the smallest average fragmentation percentage at only 61.19% compared to the other two methods which were in the low to mid 90s region. I think best fit worked the best because the program is already minimizing the amount of fragmentation by using the smallest block able to accomodate the request from the beginning.
......@@ -45,9 +45,10 @@ int main(int argc, char *argv[]){
s = rand() * (900/ (double)RAND_MAX) + 100;
p = allocate(s, algorithm);
deallocate(p);
r ++;
if (p != NULL){
deallocate(p);
r ++;
}
}
avg = average_frag();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment