From 206dce7bab107651aa56dda8559b44958dc34a66 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 1 Nov 2023 20:44:37 +0000 Subject: Heap now maintains a new page per allocation Instead of having each page be an area of memory, where multiple pointers to differing data may lie, we instead have each page being one allocation. This ensures that a deletion algorithm, as provided, would actually work without destroying older pointers which may have been allocated. Great! --- lib/heap.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'lib/heap.h') diff --git a/lib/heap.h b/lib/heap.h index b84baf0..d289ffa 100644 --- a/lib/heap.h +++ b/lib/heap.h @@ -17,17 +17,14 @@ #include -#define PAGE_DEFAULT_SIZE 64 - typedef struct Page { struct Page *next; - size_t used, available; + size_t available; byte data[]; } page_t; page_t *page_create(size_t, page_t *); -size_t page_space_left(page_t *); void page_delete(page_t *); typedef struct @@ -37,7 +34,8 @@ typedef struct } heap_t; void heap_create(heap_t *); -byte *heap_allocate(heap_t *, size_t); +void heap_free_page(heap_t *, page_t *); +page_t *heap_allocate(heap_t *, size_t); void heap_stop(heap_t *); #endif -- cgit v1.2.3-13-gbd6f