From f49256d7e7ff5b9393a156ee5e9ec340181bd4ef Mon Sep 17 00:00:00 2001 From: karutoh Date: Thu, 8 Feb 2024 02:07:49 -0800 Subject: [PATCH] Code optimization. --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index c3eddcc..65af95b 100644 --- a/main.c +++ b/main.c @@ -88,7 +88,7 @@ void* malloc(size_t size) freeList = b; } - return (char*)b + BLOCK_SIZE; + return (struct block*)b + 1; } /// Will flag the provided memory as free and will defragment other blocks adjacent to it. @@ -100,7 +100,7 @@ void free(void* ptr) if (!ptr) return; - struct block* b = (struct block*)((char*)ptr - BLOCK_SIZE); + struct block* b = (struct block*)ptr - 1; b->free = 1; struct block* link = b->next;