contributed by < Jerejere0808
>
static inline void *get_loc_to_place(void *current, int size)
{
block_t *best_fit = NULL;
block_t *parse = current;
while (parse != NULL) {
if (parse->size >= (size + header_size)) {
if (best_fit == NULL || parse->size < best_fit->size) {
best_fit = parse;
}
}
parse = parse->prev;
}
parse = ((block_t *) current)->next;
while (parse != NULL) {
if (parse->size >= (size + header_size)) {
if (best_fit == NULL || parse->size < best_fit->size) {
best_fit = parse;
}
}
parse = parse->next;
}
if (best_fit != NULL) {
return best_fit;
} else {
return NULL;
}
}