Browse Source

Continued progress on tree allocator

tree_alloc
Thomas Johnson 1 year ago
parent
commit
89f8bfe3f1
  1. 6
      allocator_internal.h
  2. 27
      tree_alloc.c

6
allocator_internal.h

@ -8,10 +8,12 @@ const char RT_FREESPACE = 0;
const char RT_TREE_NODE = 1;
const char RT_WATERMARK = 2;
struct TopLevel {
typedef struct Arena {
struct FreeSpace *root_freespace;
struct TreeAlloc *root_treealloc;
};
void *(*get_new_region)(uintptr_t);
void (*error)(char*);
} Arena;
// All three of these types should be memory-compatible with each other

27
tree_alloc.c

@ -84,8 +84,15 @@ void remove_node(TreeAlloc** root_ptr, TreeAlloc* node) {
}
}
// Inserts a node into an empty tree.
// TODO: Rewrite for self-balancing tree.
void insert_after(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* after) {
void insert_singleton(TreeAlloc **root_ptr, TreeAlloc *to_insert) {
*root_ptr = to_insert;
to_insert->parent = NULL;
}
// TODO: Rewrite for self-balancing tree.
void insert_right(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* after) {
if (after->right != NULL) {
after->right->parent = to_insert;
to_insert->right = after->right;
@ -95,7 +102,7 @@ void insert_after(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* after)
}
// TODO: Rewrite for self-balancing tree.
void insert_before(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* before) {
void insert_left(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* before) {
if (before->left != NULL) {
before->left->parent = to_insert;
to_insert->left = before->left;
@ -104,5 +111,21 @@ void insert_before(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* before
to_insert->parent = before;
}
void *unalloc(Arena *arena, void *addr) {
if (arena->root_treealloc == NULL) {
arena->error("attempt to unallocate when there are no allocations!");
}
TreeAlloc *node = search_by_address(arena->root_treealloc, addr);
// TODO
}
void *alloc(Arena arena, uintptr_t size, uintptr_t align) {
// TODO
return NULL;
}
void *alloc_growable(Arena arena, uintptr_t size, uintptr_t align) {
// TODO
return NULL;
}
Loading…
Cancel
Save