From 4947abc31c611caa7c825660bdf61ae0834a9831 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Tue, 24 May 2022 20:14:00 +0300 Subject: [PATCH] implement heap_split --- heap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/heap.c b/heap.c index 2fb959e..c041f36 100644 --- a/heap.c +++ b/heap.c @@ -14,6 +14,7 @@ typedef struct { } mblock_t; #define MBLOCK_ALLOCATED (1<<0) +#define MBLOCK_SIZE(size) ((size) & ~MBLOCK_ALLOCATED) void heap_init(mheap_t* heap, void* start, unsigned int size) { @@ -25,7 +26,13 @@ void heap_init(mheap_t* heap, void* start, unsigned int size) block->size = size; } - +void heap_split(mblock_t* block, unsigned int size) +{ + mblock_t* split = (mblock_t*)((uint8_t*)block + size); + split->prev = block; + split->size = block->size - size; + block->size = size; +} int main() {