Commit 7849b640 authored by Lindsay Knupp's avatar Lindsay Knupp
Browse files

Lab 8.1 completed

parent 41873872
......@@ -8,11 +8,10 @@ Lab 8 - answers.txt
(1.3)
double average_frag();
running average counter
pointer of first allocated block + size
pointer of second allocated block
subtract the two to see how much of a gap there is b/t the two
repeat until the node.next = null
if node.next = null
then subtract node.data + size from total length of list
largest-block = MAX_RAND
total freemem counter = 0
for block in free list
update largest-block if needed
total freemem counter += size of block
average = 1 - largestblock / total freemem counter
......@@ -37,5 +37,12 @@ void *allocate(size_t size, int alloc_type);
*/
int deallocate(void * ptr);
/**
* Calculate the average fragmentation of the
* free memory list
* @return average fragementation
*/
double average_frag();
#endif /* _ALLOCATOR_H_ */
......@@ -120,3 +120,21 @@ int deallocate(void *ptr){
return 0;
}
double average_frag(){
double largest_block = 0;
double totalfree_mem = 0;
double average;
for (curr_data = dlist_iter_begin(free_list); curr_data != NULL; curr_data = dlist_iter_next(free_list))
totalfree_mem += curr_data->size;
if (curr_data->size > largest_block) {
largest_block = curr_data->size;
}
average = (1 - largest_block) / totalfree_mem;
return average;
}
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