From e2b78d20b80d89321d8d9df3ab8ade8407642dfc Mon Sep 17 00:00:00 2001 From: Aleksa Vučković Date: Sun, 2 Jan 2022 22:56:02 +0100 Subject: Adding code --- include/08.heap/heap04.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 include/08.heap/heap04.c (limited to 'include/08.heap/heap04.c') diff --git a/include/08.heap/heap04.c b/include/08.heap/heap04.c new file mode 100644 index 0000000..be39951 --- /dev/null +++ b/include/08.heap/heap04.c @@ -0,0 +1,33 @@ +int k_heapBMAddBlock(KHEAPBM *heap, uintptr_t addr, uint32_t size, uint32_t bsize) { + KHEAPBLOCKBM *b; + uint32_t bcnt; + uint32_t x; + uint8_t *bm; + + b = (KHEAPBLOCKBM*)addr; + b->size = size - sizeof(KHEAPBLOCKBM); + b->bsize = bsize; + + b->next = heap->fblock; + heap->fblock = b; + + bcnt = b->size / b->bsize; + bm = (uint8_t*)&b[1]; + + /* clear bitmap */ + for (x = 0; x < bcnt; ++x) { + bm[x] = 0; + } + + /* reserve room for bitmap */ + bcnt = (bcnt / bsize) * bsize < bcnt ? bcnt / bsize + 1 : bcnt / bsize; + for (x = 0; x < bcnt; ++x) { + bm[x] = 5; + } + + b->lfb = bcnt - 1; + + b->used = bcnt; + + return 1; +} -- cgit v1.2.3