From 04b57a756402e156953edfa2079d69b41db26e51 Mon Sep 17 00:00:00 2001 From: "Douglas B. Rumbaugh" Date: Sun, 2 Nov 2025 15:39:43 -0500 Subject: Updated free list interface I realized my existing interface wouldn't work if the coalescing or adding of a new node replaced the head of the list, as there was no way to communicate that back to the caller. As a result, I've updated those interfaces to accept a pointer to the free list head pointer. This will let them change the free list head in alloc.c if necessary. --- src/alloc.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/alloc.c b/src/alloc.c index c13b1e8..830e49f 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -12,13 +12,7 @@ #include "alloc.h" #include "constants.h" #include "free_list.h" - -typedef struct header { - size_t size; - size_t magic_number; -} header; - -static_assert(sizeof(header) % ALIGNMENT == 0, "Header improperly aligned"); +#include "alloc_header.h" static void *heap_start = 0; static void *heap_end = 0; @@ -59,7 +53,7 @@ void *allocate(size_t size) { /* first check for a suitable memory block on the free list */ free_nd *nd = fl_find_first_fit(free_list, size); if (nd) { - void *return_region = fl_split_node(free_list, nd, size); + void *return_region = fl_split_node(&free_list, nd, size); } /* @@ -82,6 +76,6 @@ void *allocate(size_t size) { } void release(void *ptr) { - fl_add_node(free_list, ptr); + fl_add_node(&free_list, ptr); fl_coalesce_nodes(free_list); } -- cgit v1.2.3