On Tue, 28 Sep 1999, Fergus Henderson wrote:
> > Personally I'd
> > always write the above, not so much for performance reasons as the fact
> > that if the objects in the vector have a shallow copy constructor
> > (generated automatically & silently) but a destructor that deallocates
> > resources you've got an awful mess to debug when it crashes after leaving
> > the function; consequently I do this even when it isn't strictly
> > necessary. The few other C++ programmers I know do the same thing so
> > it's probably reasonable to assume everyone does.
>
> That's not a reasonable assumption. If you have a class which has a
> shallow copy constructor but a destructor that deallocates resources,
> then you're already in deep trouble. Passing by const reference in
> such a case will at best only stave off the inevitable disaster.
>
> Your conclusion is correct, in this case, but the motivation should
> be performance, not defending against buggy code with mismatched
> destructors and copy-constructors.
<wearing image processing researchers hat>
staving off disaster might make things not fall over long enough for me to
get some results out when I'm using buggy classes that I've written (very
rare: a couple of long debug sessions have made me paranoid about this) or
buggy classes/plain C structs that come from someone elses code.
I entirely agree this isn't suitable for misssion critical/long liftime
code, but my supervisor's next student can sue me for writing
non-maintainable code if he can find me :-)
</wearing image processing researchers hat>
Anyway, my reason for digressing like that in the original mail was to
suggest that it wasn't necessarily an obscure performance improvement
technique but something I often need anyway to get correct code.
___cheers,_dave______________________________________________________
email: [EMAIL PROTECTED] "He'd stay up all night inventing an
www.cs.bris.ac.uk/~tweed/pi.htm alarm clock to ensure he woke early
work tel: (0117) 954-5253 the next morning"-- Terry Pratchett