Modified best_fit()
parent
2a4dd8d48d
commit
85abbe732b
11
mm.c
11
mm.c
|
@ -157,12 +157,17 @@ static int getSzClass(size_t asize) {
|
||||||
|
|
||||||
static void* best_fit(void* ptr, size_t asize) {
|
static void* best_fit(void* ptr, size_t asize) {
|
||||||
unsigned long left_over = GET_SIZE(ptr) - 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) {
|
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);
|
ptr = NXT_FREE(ptr);
|
||||||
}
|
}
|
||||||
return NULL;
|
return bestfit;
|
||||||
}
|
}
|
||||||
/* Page 856, Pearson R. Bryant – D. O’Hallaron. Computer Systems: A Programmer’s Perspective.3rd Edition, Pearson, 2003. */
|
/* Page 856, Pearson R. Bryant – D. O’Hallaron. Computer Systems: A Programmer’s Perspective.3rd Edition, Pearson, 2003. */
|
||||||
static void* find_fit(size_t asize)
|
static void* find_fit(size_t asize)
|
||||||
|
|
Loading…
Reference in New Issue