Skip to content

Commit 8241b04

Browse files
Merge pull request #6 from llucinat/fix-heap-init
Fix heap initialization
2 parents 822743c + 3bbef73 commit 8241b04

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

tinyalloc.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ typedef struct {
2222
Block *used; // first used block
2323
Block *fresh; // first available blank block
2424
size_t top; // top free addr
25-
Block *blocks;
2625
} Heap;
2726

2827
static Heap *heap = NULL;
@@ -121,11 +120,10 @@ bool ta_init(const void *base, const void *limit, const size_t heap_blocks, cons
121120

122121
heap->free = NULL;
123122
heap->used = NULL;
124-
heap->fresh = heap->blocks;
125-
heap->top = (size_t)base + sizeof(Heap) + heap_blocks * sizeof(Block);
126-
heap->blocks = (Block*) (base + sizeof(Heap));
123+
heap->fresh = (Block *)(heap + 1);
124+
heap->top = (size_t)(heap->fresh + heap_blocks);
127125

128-
Block *block = heap->blocks;
126+
Block *block = heap->fresh;
129127
size_t i = heap_max_blocks - 1;
130128
while (i--) {
131129
block->next = block + 1;

0 commit comments

Comments
 (0)