Modified best_fit()

master
anna_schlittenhardt 2021-01-24 16:56:45 +01:00
parent 2a4dd8d48d
commit 85abbe732b
1 changed files with 8 additions and 3 deletions

11
mm.c
View File

@ -157,12 +157,17 @@ static int getSzClass(size_t asize) {
static void* best_fit(void* ptr, size_t asize) {
unsigned long left_over = GET_SIZE(ptr) - asize;
int c = 0;
void* bestfit = ptr;
int best_left_over = GET_SIZE(ptr) - asize);
while (NXT_FREE(ptr) != NULL) {
left_over = (MIN(left_over, GET_SIZE(ptr) - asize));
left_over = GET_SIZE(ptr) - asize);
if(left_over<best_left_over){
best_left_over = left_over;
bestfit=ptr;
}
ptr = NXT_FREE(ptr);
}
return NULL;
return bestfit;
}
/* Page 856, Pearson R. Bryant D. OHallaron. Computer Systems: A Programmers Perspective.3rd Edition, Pearson, 2003. */
static void* find_fit(size_t asize)