Heap free size measuring functions

Joel Sherrill joel.sherrill at OARcorp.com
Thu Oct 12 15:18:05 UTC 2000


Nick.SIMON at syntegra.bt.co.uk wrote:
> 
> Chaps,
> 
> I need to be able to monitor the heap for diagnostics.  I have writen a
> function _Heap_Scan for the kernel end of things, and had planned to put a
> library function in malloc.c.
> 
> 2 questions:
> 
>  - Is it OK to put stuff in libc

Yes.  But the current stuff in src/lib/libc is a bit broad and will
likely get scattered over the next few months.  Especially the
filesystem
stuff is a bit heavy in there.

>  - Is there a standard function template "out there" that this could conform
> to?

A few ideas in no particular order:

  1.  There is some statistics code in the malloc.c file.
  2.  There are no statistics code for the heap object in the SuperCore.
  3.  The _Heap_Walk (src/exec/score/src) is complicated but loops over
      the entire heap.  _Heap_Allocate has a loop to scan for a block of 
      the desired size on the free block list.
  4.  _Heap_Walk() walks the heap data structure and is probably the
better
      starting point if you want used/free information.
  5.  block size and used information is kept in the front_flag.  
  6.  If the heap has been extended, we identified 5 cases.  The only
one
      that is valid and supported does not confuse things since it is
      extending in a contiguous manner.  BUT ... if cases 1 and 5 were
      ever supported, it might confuse the extended count.  See the 
      list of possibilities in a comment in heapextend.c. 

> Regards,
> 
> -- Nick Simon

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp.com                 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