"mallinfo" in GPC?
frank at g-n-u.de
Sat Mar 17 00:26:01 CET 2001
Eike Lange wrote:
> On Fri, Mar 16, 2001 at 08:13:40AM -0300, Tomasz Kowaltowski wrote:
> > In gcc one can use the function "mallinfo()" in order to know, among
> > other things, the amount of dynamic storage currently allocated by the
> > program through "malloc()". I use it to check for program memory
> > leaks.
> > I would like to know whether there is anything similar for gpc?
> I didn't find mallinfo in the info file of gpc, but you can use this:
AFAICS, it's a function in glibc and apparently a few other systems'
libc, but not available on all systems. Using GCC/GPC does not mean
using glibc, of course, so you can't assume it to be present.
If it is present and you want to use it, fine (Eike showed a way how
to), otherwise, as The Chief mentioned, `AllocMemSize' and
`AllocMemCount' in the System provide some of the information
mallinfo() does, though they have a little runtime overhead, but if
it's only for debugging, this shouldn't matter.
Either way, you'll find that a few memory blocks are allocated
beyond your control. The Run Time System uses them, e.g. to keep
track of opened files, finalization routines, etc.
BTW, for a quite primitive memory leap checking, you can use the
included HeapMon unit. Just put `uses HeapMon;' in your program, and
at the end of the program, the unit will complain if any pointers
were not deallocated. It does quite the same as `AllocMemCount' and
has the same runtime overhead. Since it initializes itself in its
initializer and checks the memory in its finalizer (and finalizers
are run in the opposite order as initializers), there should be no
memory allocated for finalizers or open files (provided you closed
all your files), i.e. no "false alarms"...
Frank Heckenbach, frank at g-n-u.de, http://fjf.gnu.de/
GPC To-Do list, latest features, fixed bugs:
More information about the Gpc