Added get_heap_size function.

This commit is contained in:
Arron David Nelson 2024-02-08 18:50:58 -08:00
parent 9594b76202
commit 0e2633db9d

8
main.c
View File

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