diff options
| author | Aleksa Vučković <aleksav013@gmail.com> | 2022-01-02 22:56:02 +0100 |
|---|---|---|
| committer | Aleksa Vučković <aleksav013@gmail.com> | 2022-01-02 22:56:02 +0100 |
| commit | e2b78d20b80d89321d8d9df3ab8ade8407642dfc (patch) | |
| tree | 148cb3bc894b974ae91290e493046120d04987b0 /include/08.heap/heap04.c | |
| parent | ead31873b971044cd3ecb7e40ae03bdb2e6f7642 (diff) | |
Adding code
Diffstat (limited to 'include/08.heap/heap04.c')
| -rw-r--r-- | include/08.heap/heap04.c | 33 |
1 files changed, 33 insertions, 0 deletions
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; +} |
