Preventing/handling space leaks

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Dec 9 19:19:56 EST 2003


On 08-Dec-2003, ajb at spamcop.net <ajb at spamcop.net> wrote:
> G'day all.
> 
> Quoting Sven Panne <Sven.Panne at aedion.de>:
> 
> > Granted, C++'s (copy) constructors, destructors and assignment operators
> > make some things relatively easy compared to C, but the complexity of
> > handling exceptions *correctly* makes things worse again: There is
> > a famous article (I can't remember the title or the author) where a
> > well-known C++ grandmaster explains a stack class, but another later
> > article by someone else describes the numerous bugs in that class when
> > exceptions are taken into account.
> 
> Far be it from me to defend C++, but this problem is far better understood
> today than when that GoTW article (circa 1996, from memory) was written.

The problems are certainly better understood.  But they are also
certainly NOT understood well enough for programmers to be able to
reliably avoid them.

Even the C++ standard library itself, which has been
subject to review by the world's best C++ experts, suffers
from exception safety problems.  A new exception safety
problem with std::auto_ptr was discovered just last Friday!  See
<http://groups.google.com.au/groups?selm=uptf3hzya.fsf%40boost-consulting.com>.

Note that this class has already been the subject of extensive analysis
of its exception safety, and indeed the only reason that auto_ptr
was introduced in the first place was in an attempt to help guarantee
exception safety!

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.


More information about the Haskell-Cafe mailing list