Commit 070277c1 authored by Lindsay Knupp's avatar Lindsay Knupp
Browse files

Lab 8.2 completed

parent 7849b640
......@@ -42,6 +42,8 @@ memory-test2: $(SRC)/memory-test2.c $(OBJ)/dnode.o $(OBJ)/dlist.o $(OBJ)/allocat
memory-test3: $(SRC)/memory-test3.c $(OBJ)/dnode.o $(OBJ)/dlist.o $(OBJ)/allocator.o
$(CC) $(CFLAGS) $(OBJ)/dnode.o $(OBJ)/dlist.o $(OBJ)/allocator.o $(SRC)/memory-test3.c -o $(BIN)/memory-test3
frag-eval: $(SRC)/frag-eval.c $(OBJ)/dnode.o $(OBJ)/dlist.o $(OBJ)/allocator.o
$(CC) $(CFLAGS) $(OBJ)/dnode.o $(OBJ)/dlist.o $(OBJ)/allocator.o $(SRC)/frag-eval.c -o $(BIN)/frag-eval
......
......@@ -15,3 +15,9 @@ double average_frag();
update largest-block if needed
total freemem counter += size of block
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.
I used the pseudo-code given to me in the lab.
......@@ -121,19 +121,21 @@ int deallocate(void *ptr){
}
double average_frag(){
struct dnode *curr_data;
double average;
double totalfree_mem;
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))
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;
}
average = 1 - (largest_block / totalfree_mem);
return average;
......
/**
* Lindsay Knupp
* 11/15/21
* Lab 8 - frag-eval.c
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "allocator.h"
#include "dlist.h"
int main(int argc, char *argv[]){
int algorithm;
unsigned int seed;
int requests;
if (argc < 4) {
printf("Usage: %s [algorithm] [seed] [requests]\n", argv[0]);
exit(-1);
}
else{
algorithm = atoi(argv[1]);
seed = atoi(argv[2]);
requests = atoi(argv[3]);
}
// Initialize memory lists
allocator_init(10240);
printf("Frag-eval running\n");
srand(seed); //initialize PRNG
double avg;
int r = 0;
void *p = NULL;
int s;
while (r < requests){
s = rand() * (900/ (double)RAND_MAX) + 100;
p = allocate(s, algorithm);
deallocate(p);
r ++;
}
avg = average_frag();
printf("Average fragmentation: %lf\n",avg);
}
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