[C++-sig] Re: Doubts with wrapping/using abstract bases.
RaoulGough at yahoo.co.uk
Sun Aug 17 00:08:16 CEST 2003
Prabhu Ramachandran <prabhu at aero.iitm.ernet.in> writes:
>>>>>> "RG" == Raoul Gough <RaoulGough at yahoo.co.uk> writes:
> [snip explanation by RG of how test_holder.py works]
> Thanks for the explanation, it confirmed my understanding!
Well, I'm glad to hear that it made sense! I wasn't too sure about the
details myself, before I started my previous post.
> RG> BTW, have you considered using boost::shared_ptr? I wouldn't
> RG> trust std::auto_ptr with this kind of stuff. Also, storing raw
> RG> pointers in a vector is just asking for trouble if you ask me.
> Dave enlightened me on the advantages of using boost::shared_ptr a
> month or so back. Unfortunately I am not in a position to change my
> code at this time for two reasons: (a) I'll need to investigate if
> there is a performance hit for my kind of code (b) I don't have the
> time to change the interface in my code right now and carefully
> eliminate cyclic reference loops etc.
I see. Cyclic references would mean that you can't blindly replace
everything with shared_ptr, so you'd have to decide on using some kind
of weak pointer (e.g. raw pointers or boost::weak_ptr) at strategic
locations. BTW, I once wrote a checked pointer that detects mis-uses
in debug builds, but can be compiled away in release builds (similar
to an assert macro). Details at
http://home.clara.net/raoulgough/weak_ptr/, but it is more theoretical
exercise than production-strength code.
> Storing pointers in a vector is asking for trouble? It might be true
> in general but I'd say using pointers carefully is not bad. It has
> worked well for me so far.
Well, I was thinking specifically about mixing raw pointers in a
container with std::auto_ptr pointers elsewhere. I'd be worried about
the chances of an auto_ptr deciding to delete a pointer that is still
stored in the vector. That's apart from the usual risk of memory
leaks, of course. I'm not saying it can't be done, just that I
wouldn't find it particularly easy. OTOH, I can understand why
changing over wouldn't be feasible in an existing development process
- it might end up costing you more time to switch over than it would
save in debugging.
"Let there be one measure for wine throughout our kingdom, and one
measure for ale, and one measure for corn" - Magna Carta
More information about the Cplusplus-sig