Need help monitoring malloc() and free()

D. Richard Hipp drh at duke.cs.duke.edu
Mon Jan 21 22:56:50 AEST 1991


In article <1991Jan20.185009.18694 at cbnews.att.com> res at cbnews.att.com (Robert E. Stampfli) writes:
>>What I was thinking is making a front end to malloc() and free(), so
>>all calls to malloc() would actually call my routine and my routine
>>would in turn call the malloc() that lives in libc.a.
>
>Have you tried compiling your program with "-Dmalloc=Mymalloc -Dfree=Myfree"
>on the compile line?  Obviously, you leave this off the step that compiles
>your liaison code -- the actual instance of Mymalloc() and Myfree().

An alternative would be to include the following lines at the beginning
of the file containing your liaison code:

#ifdef malloc
#undef malloc
#endif

#ifdef free
#undef free
#endif

This way, the "-Dmalloc=MyMalloc" defines could be specified with the
CFLAGS macro in your makefile.



More information about the Comp.unix.programmer mailing list