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);