Skip to content
Snippets Groups Projects
Commit 2e2806fb authored by DocQuantum's avatar DocQuantum
Browse files

Changed to next-fit algorithm, moving perf to 85%

parent 38f51c32
No related branches found
No related tags found
No related merge requests found
......@@ -641,16 +641,32 @@ static void *find_fit(size_t asize)
return NULL;
}
/* first fit search */
/* Next fit search */
void *bp = free_listp;
void *bestP = bp;
void *first = NULL;
short flag = 0;
do {
if (asize <= GET_SIZE(HDRP(bp))) {
return bp;
if (GET_SIZE(HDRP(bp)) >= asize) {
if(GET_SIZE(HDRP(bestP)) > GET_SIZE(HDRP(bp))){
bestP = bp;
flag++;
}
if(!flag){
first = bp;
flag = 1;
}
if(flag == 2){
break;
}
if((bp = GET_NEXT_FREE(bp)) == NULL){
return NULL;
}
bp = GET_PREV_FREE(bp);
} while(bp != free_listp);
if(asize <= GET_SIZE(HDRP(bestP))){
return bestP;
} else if(first != NULL){
return first;
}
return NULL; /* no fit */
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment