6 #include <linkedlist/ll.h> 11 #pragma mark - Definitions - 18 #define align_up(num, align) (((num) + ((align)-1)) & ~((align)-1)) 37 #define ALLOC_HEADER_SZ offsetof(alloc_node_t, block) 40 #define MIN_ALLOC_SZ ALLOC_HEADER_SZ + 32 42 #pragma mark - Prototypes - 46 #pragma mark - Declarations - 51 #pragma mark - Private Functions - 64 list_for_each_entry_safe(b, t, &free_list, node)
68 if((((uintptr_t)&lb->
block) + lb->
size) == (uintptr_t)b)
70 lb->
size +=
sizeof(*b) + b->size;
95 size =
align_up(size,
sizeof(
void*));
98 list_for_each_entry(blk, &free_list, node)
100 if(blk->
size >= size)
117 list_insert(&new_blk->
node, &blk->
node, blk->
node.next);
120 list_del(&blk->
node);
140 list_for_each_entry(free_blk, &free_list, node)
144 list_insert(&blk->
node, free_blk->
node.prev, &free_blk->
node);
148 list_add_tail(&blk->
node, &free_list);
161 blk = (
void*)
align_up((uintptr_t)addr,
sizeof(
void*));
167 list_add(&blk->
node, &free_list);
static LIST_INIT(free_list)
static void defrag_free_list(void)
void malloc_addblock(void *addr, size_t size)
Assign blocks of memory for use by malloc().
#define align_up(num, align)
void * malloc(size_t size)
void malloc_init(void)
Initialize Malloc.