aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDouglas B. Rumbaugh <doug@douglasrumbaugh.com>2025-11-02 16:08:52 -0500
committerDouglas B. Rumbaugh <doug@douglasrumbaugh.com>2025-11-02 16:08:52 -0500
commit2347c038520bc3dc6f3990a6b088d4aa8fd17c7a (patch)
tree59e894486861ac13197dd26fdbcfa4ac8a337876 /src
parent5d8131a4240e4dab0e519bd3e29e3cabf5f09672 (diff)
downloadliballoc-2347c038520bc3dc6f3990a6b088d4aa8fd17c7a.tar.gz
free_list: partial split implementation
Implemented enough of split to get basic free list reuse working. Also updated the allocate() function to return the output of split when it is called.
Diffstat (limited to 'src')
-rw-r--r--src/alloc.c2
-rw-r--r--src/free_list.c20
2 files changed, 19 insertions, 3 deletions
diff --git a/src/alloc.c b/src/alloc.c
index dd1c8aa..3f805db 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -53,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);
+ return fl_split_node(&free_list, nd, size);
}
/*
diff --git a/src/free_list.c b/src/free_list.c
index 31244fb..ee9e571 100644
--- a/src/free_list.c
+++ b/src/free_list.c
@@ -21,8 +21,24 @@ free_nd *fl_find_first_fit(free_nd *free_list, size_t size) {
return NULL;
}
-void *fl_split_node(free_nd **free_list, free_nd *nd, size_t size) {
- return NULL;
+void *fl_split_node(free_nd **free_list, free_nd *split_nd, size_t size) {
+ /* for now, we'll just remove the node from the free list */
+
+ if (*free_list == split_nd) {
+ *free_list = (*free_list)->next;
+ }
+
+ for (free_nd *nd = *free_list; nd; nd = nd->next) {
+ if (nd->next == split_nd) {
+ /*
+ * split_nd is not null, so we know that nd->next is
+ * also not null here
+ */
+ nd->next = nd->next->next;
+ }
+ }
+
+ return split_nd;
}
void fl_coalesce_nodes(free_nd *free_list) {