Added get_heap_size function.
This commit is contained in:
parent
9594b76202
commit
0e2633db9d
8
main.c
8
main.c
@ -153,6 +153,13 @@ void free(void* ptr)
|
|||||||
brk(b);
|
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 main()
|
||||||
{
|
{
|
||||||
int* a = (int*)malloc(sizeof(int));
|
int* a = (int*)malloc(sizeof(int));
|
||||||
@ -163,6 +170,7 @@ int main()
|
|||||||
|
|
||||||
printf("Test 1: %i\n", *a);
|
printf("Test 1: %i\n", *a);
|
||||||
printf("Test 2: %i\n", *b);
|
printf("Test 2: %i\n", *b);
|
||||||
|
printf("Heap Size: %zu Bytes\n", get_heap_size());
|
||||||
|
|
||||||
free(a);
|
free(a);
|
||||||
free(b);
|
free(b);
|
||||||
|
Loading…
Reference in New Issue
Block a user