aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarsten Schmidt <k@postspectacular.com>2020-08-06 11:10:09 +0100
committerGitHub <noreply@github.com>2020-08-06 11:10:09 +0100
commit8241b04999909769bdbd0046c3a2200cfed72367 (patch)
tree4725477116b8084ca110428047feda4c1feefa7c
parent822743cd25fb24ccbba6bc88c289d4af67c47974 (diff)
parent3bbef7348b5127406af64a69eae33cff4c3eb818 (diff)
Merge pull request #6 from llucinat/fix-heap-init
Fix heap initialization
-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;