Memory region tracking similar to malloc_stats?

Joel Sherrill joel.sherrill at
Tue Sep 11 16:07:43 UTC 2001

Phil Torre wrote:
> Is there a simple way to access the current amount of space remaining
> in a region?  Something like malloc_stats would be great, but I don't
> actually need the allocation history so much as the current free
> space (so as to watch for get_segment/return_segment leaks).
> It looks like the right thing to do is to walk the heap blocks like
> _Heap_Allocate() does, but I'll save myself some fumbling around if
> this work has already been done.  Thanks...

How about this routine? :)

 *  Find amount of free heap remaining

size_t malloc_free_space( void )

It is based on the rtems_region_get_information()
call.  It can return the following info:

 *  Information block returned by _Heap_Get_information

typedef struct {
  unsigned32   free_blocks;
  unsigned32   free_size;
  unsigned32   used_blocks;
  unsigned32   used_size;
} Heap_Information_block;

> --
> =====================================================================
> Phil Torre                               phone: 425-820-6363 x234
> Design Engineer                          email: ptorre at
> Switching Systems Group                    fax: 425-820-7031
> Zetron, Inc.                               web:

Joel Sherrill, Ph.D.             Director of Research & Development
joel at                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985

More information about the users mailing list