static void *next_fit(size_t asize) { void *bp = last_block; int wraps = 0; while(GET_SIZE(HDRP(bp)) > 0){ if(wraps > 0 && bp == last_block) // We went through the whole thing return NULL; if(!GET_ALLOC(HDRP(bp) && (asize <= GET_SIZE(HDRP(bp))) { last_block = bp; return bp } bp = NEXT_BLKP(bp); if(GET_SIZE(HDRP(bp)) <= 0){ // We hit the end, need wrap around bp = heap_listp; wraps++; } // end if } // end while } // end next_fit