diff options
author | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-12-27 21:05:20 +0100 |
---|---|---|
committer | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-12-27 21:05:20 +0100 |
commit | 4dbe0373535bc37ef5e2c78f1f8c5d2aa22c3344 (patch) | |
tree | 914dc2f2f660a7f43e5f324ef5d531171dcd8f42 | |
parent | 3fe65cf3ca26410b77bbf179ecc57884fcce7775 (diff) |
clang...
-rw-r--r-- | mm.c | 31 |
1 files changed, 14 insertions, 17 deletions
@@ -8,22 +8,22 @@ * coalescing. * * --=[ APPROACH TO THE PROBLEM ]=-- - * + * * This is the list of steps I did in order to implement this solution: * 1. Implemented implicit list of free and used blocks, made it work with * simple first-fit policy. - * 2. Implemented doubly linked list and many policies of inserting and + * 2. Implemented doubly linked list and many policies of inserting and * searching for the block. * 3. Debuged allocator functions, optimised realloc. * 4. Abstracted functions related to free block management. - * 5. Now, when I had a working allocator code I could just implement the + * 5. Now, when I had a working allocator code I could just implement the * interface for free block management with splay trees. It worked almost * instantly after implementing. It made the code work 10 times faster. * 6. Further micro optimisations. - * + * * Along the way I've implement a lot of auxilary debug functions. I tried my * best to keep the code as clean as possible. - * + * * --=[ MANAGING USED AND FREE BLOCK ]=-- * * Used blocks structure: @@ -779,7 +779,7 @@ static void reduce_block(used_block_t *block, size_t old_sz, size_t new_sz) { static bool maybe_extend_block(used_block_t *block, size_t cur_sz, size_t sz) { free_block_t *next = next_block(block); size_t sz_both = cur_sz + get_size(next); - if (sz_both < sz) + if (sz_both < sz) return false; erase_fb(next); make_used(block, sz, is_prevfree(block)); @@ -787,8 +787,7 @@ static bool maybe_extend_block(used_block_t *block, size_t cur_sz, size_t sz) { maybe_clr_next_prevfree(block); if (next == last) last = block; - } - else { + } else { free_block_t *new_next = (free_block_t *)next_block(block); make_free(new_next, sz_both - sz, 0); if (last == next) @@ -804,12 +803,10 @@ static bool maybe_realloc_inplace(used_block_t *block, size_t sz) { size_t cur_sz = get_size(block); if (cur_sz == sz) { return true; - } - else if (cur_sz > sz) { + } else if (cur_sz > sz) { reduce_block(block, cur_sz, sz); return true; - } - else if (is_next_free(block)) { + } else if (is_next_free(block)) { return maybe_extend_block(block, cur_sz, sz); } return false; @@ -837,7 +834,7 @@ static void *realloc_to_new_block(used_block_t *block, size_t sz) { // make_used(prev, sz, 0); // copy_block_payload(prev, block); // if (both_sz == sz) { -// if (last == block) +// if (last == block) // last = prev; // } // else { /* both_sz > sz */ @@ -866,13 +863,13 @@ void *realloc(void *old_ptr, size_t size) { if (maybe_realloc_inplace(block, size)) { old_ptr = get_payload(block); } - // else if (is_prevfree(block) && (old_ptr = maybe_extend_to_left(block, size))) { - // ; + // else if (is_prevfree(block) && (old_ptr = maybe_extend_to_left(block, + // size))) { + // ; // } else if (block == last) { old_ptr = realloc_to_heap_end(block, size); - } - else { + } else { old_ptr = realloc_to_new_block(block, size); } print_heap(); |