Datasheet
The C and C++ Libraries
ARM DUI 0067D Copyright © 1999-2001 ARM Limited. All rights reserved. 4-103
Example 4-20 heapstats output
32272 bytes in 2 free blocks (avge size 16136)
1 blocks 2^12+1 to 2^13
1 blocks 2^13+1 to 2^14
The function outputs its results by calling the output function
dprint
, which must work
like
fprintf()
. The first parameter passed to
dprint
is the supplied pointer
param
. You
can pass
fprintf()
itself, provided you cast it to the right function pointer type. This
type is defined as a
typedef
for convenience. It is called
__heapprt
. For example:
__heapstats((__heapprt)fprintf, stderr);
Note
If you call
fprintf()
on a stream that you have not already sent output to, the library
calls
malloc()
internally to create a buffer for the stream. If this happens in the middle
of a call to
__heapstats()
, the heap might be corrupted. You must therefore ensure you
have already sent some output to
stderr
in the above example.
If you are using the default single-region memory model, heap memory is allocated only
as it is required. This means that the amount of free heap changes as you allocate and
deallocate memory. For example, as sequence such as:
int *ip;
__heapstats((__heapprt)fprintf,stderr); // print initial free heap size
ip = malloc(200000);
free(ip);
__heapstats((__heapprt)fprintf,stderr); // print heap size after freeing
gives output such as:
4076 bytes in 1 free blocks (avge size 4076)
1 blocks 2^10+1 to 2^11
2008180 bytes in 1 free blocks (avge size 2008180)
1 blocks 2^19+1 to 2^20
This function is an ARM-specific library extension.
Syntax
void __heapstats(int (*dprint)( void*param, char const *format,...), void*
param)