Re: To use or not to use smart pointers?
On Jul 19, 12:31 am, "Dennis Jones" <nos...@nospam.com> wrote:
"Martijn van Buul" <p...@dohd.org> wrote in messagenews:slrnf9t0rm.2gfu.p=
ino@mud.stack.nl...
* Dennis Jones:
There is no performance impact (that I know of), and the advantages
(automatic and correct object/resource lifetime management,
Automatic? Yes. Correct ? In your wildest dreams.
Okay, how about when used correctly?
Which means sparingly, then fine. I use my own reference
counted pointer in certain cases (a lot less, of course, since
I discovered the Boehm collector). But those cases are rather
the exceptions. In my experience, most (not all, but most) C++
object fall into two large categories: values and entity
objects. The first should almost never be allocated
dynamically, so the issue doesn't come up, and the second have
very arbitrary lifetimes depending on external events, so
typical smart pointers don't apply. The major use of smart
pointers I've had in the past was for "agents": small
polymorphic objects which, from a logical point of view, should
probably be copied, but because they are polymorphic, can't be.
Since such agents never own any real resources, however (except
the memory they reside in), the use of the Boehm collector has
made the use of smart pointers for them pretty much superfluous.
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34