aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDouglas B. Rumbaugh <doug@douglasrumbaugh.com>2025-11-02 15:39:43 -0500
committerDouglas B. Rumbaugh <doug@douglasrumbaugh.com>2025-11-02 15:39:43 -0500
commit04b57a756402e156953edfa2079d69b41db26e51 (patch)
tree8bbfc5301c960a72b67918f37456460e23e496ba /src
parent24d5cd8e806477b0fd2ddb5a232e672707f0da34 (diff)
downloadliballoc-04b57a756402e156953edfa2079d69b41db26e51.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/alloc.c12
1 files changed, 3 insertions, 9 deletions
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);
}