aboutsummaryrefslogtreecommitdiff
path: root/tinyalloc.c
diff options
context:
space:
mode:
authorllucinat <llucinat@dreamt.world>2019-09-05 15:07:02 +0200
committerllucinat <llucinat@dreamt.world>2020-08-06 02:24:18 +0200
commit3bbef7348b5127406af64a69eae33cff4c3eb818 (patch)
tree4725477116b8084ca110428047feda4c1feefa7c /tinyalloc.c
parent822743cd25fb24ccbba6bc88c289d4af67c47974 (diff)
Fix heap initialization
Diffstat (limited to 'tinyalloc.c')
-rw-r--r--tinyalloc.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/tinyalloc.c b/tinyalloc.c
index 5d2e82d..eb9fa3f 100644
--- a/tinyalloc.c
+++ b/tinyalloc.c
@@ -22,7 +22,6 @@ typedef struct {
Block *used; // first used block
Block *fresh; // first available blank block
size_t top; // top free addr
- Block *blocks;
} Heap;
static Heap *heap = NULL;
@@ -121,11 +120,10 @@ bool ta_init(const void *base, const void *limit, const size_t heap_blocks, cons
heap->free = NULL;
heap->used = NULL;
- heap->fresh = heap->blocks;
- heap->top = (size_t)base + sizeof(Heap) + heap_blocks * sizeof(Block);
- heap->blocks = (Block*) (base + sizeof(Heap));
+ heap->fresh = (Block *)(heap + 1);
+ heap->top = (size_t)(heap->fresh + heap_blocks);
- Block *block = heap->blocks;
+ Block *block = heap->fresh;
size_t i = heap_max_blocks - 1;
while (i--) {
block->next = block + 1;