summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2021-12-12 14:07:49 -0500
committerJon Santmyer <jon@jonsantmyer.com>2021-12-12 14:07:49 -0500
commit9b8971df9a130daf42bc12fadb8ffa32fe16d499 (patch)
treef3e5fcce84acaab7783b9deadbb0457d850f69e1
parent1b5cc0d201dc317935fb7585aa54e1489bee1caf (diff)
downloaddiheap-9b8971df9a130daf42bc12fadb8ffa32fe16d499.tar.gz
diheap-9b8971df9a130daf42bc12fadb8ffa32fe16d499.tar.bz2
diheap-9b8971df9a130daf42bc12fadb8ffa32fe16d499.zip
fix heap used memory disparity
-rw-r--r--heap.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/heap.c b/heap.c
index a57a45d..777be78 100644
--- a/heap.c
+++ b/heap.c
@@ -157,8 +157,11 @@ __heap_bucket_append(struct heap *heap, struct bucket *bucket, size_t size)
if(free->next != NULL) free->next->prev = free;
bucket->next = free;
- /*Fix heap buckets_head*/
- if(free->next == NULL) heap->buckets_head = free;
+ /*Mark up to head used memory*/
+ if(free->next == NULL) {
+ heap->used += bestfit->sizetaken;
+ heap->buckets_head = free;
+ }
/*Populate free bucket*/
free->address = bucket->address + bucket->sizetaken;
@@ -258,8 +261,6 @@ heap_alloc(struct heap *heap, size_t size)
/*Split bucket into perfectly sized piece*/
__heap_bucket_split(heap, bestfit, size);
- /*Take memory in heap, mark bucket as taken*/
- heap->used += bestfit->sizetaken;
bestfit->sizetaken |= 1;
return (void*)bestfit->address;
}