From 0e2633db9dd97b0ea02c60de2163d433947cacdf Mon Sep 17 00:00:00 2001 From: karutoh Date: Thu, 8 Feb 2024 18:50:58 -0800 Subject: [PATCH] Added get_heap_size function. --- main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.c b/main.c index f88eb07..dc86001 100644 --- a/main.c +++ b/main.c @@ -153,6 +153,13 @@ void free(void* ptr) brk(b); } +/// Retrieves the total heap usage in bytes. +/// @returns Usage in bytes. +size_t get_heap_size() +{ + return ((char*)last + last->size) - (char*)first; +} + int main() { int* a = (int*)malloc(sizeof(int)); @@ -163,6 +170,7 @@ int main() printf("Test 1: %i\n", *a); printf("Test 2: %i\n", *b); + printf("Heap Size: %zu Bytes\n", get_heap_size()); free(a); free(b);