[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: memory debugging and C++



On Sun, Sep 29, 2002 at 12:54:27PM +1000, Brian May wrote:
> I am getting lost in all of these memory debugging packages.
> 
> What is a good one for C++?

I do almost all of my coding with C++.  I tried dmalloc and was
disappointed.  I have gotten electric fence to work, but it doesn't
really do what I want which is track individual allocations and help
determine if something is leaking.  It is really good at funding
overruns, but I see those so seldom that I turned to writing my own.

After some sleuthing, I wrote an alloc class that can be used to
allocate all of the C++ objects.  It may not appear to be the 'clean'
interface given by the other packages, but that's because there
doesn't appear to be a clean method for intercepting all memory
allocation calls.  In fact, there are some calls in the libraries that
are really hard to trap.  I attempt to catch malloc calls when someone
makes them unwittingly, but you are better off auditing preprocessed
source files to make sure there are no stray references.

You can fetch it from 

  <ftp://ftp.buici.com/pub/allocator>

The most important part is in the header because that is what links
into STL.  AFAIK, these should also work with ANSI compliant
templates.  Also, you will notice a little bit of shenanigans having
to do with differences between version 2 and version 3 of the
libraries.  It does support GCC-3.x.

You pass Alloc as the allocator for standard template objects.  New
and malloc calls ought to be properly caught.

Hope this helps.



Reply to: