Date: 2002-03-25 05:17:01
> From: Juan Carlos Arevalo-Baeza
> This is why I devised a different manner of initialization
> on my (yes, I use my own, like many others) smart pointer library.
I find this quite interesting - what is (are) the reason(s) for rolling your
own rather than using the Boost smart pointers?
> When a smart pointer is given a preallocated pointer, it
> assumes that someone already owns it, and wants to share this
> ownership, so the reference counter is initialized to 2
> instead of 1. This gets rid of E's original problem.
Yes, but of course, this is just a different tradeoff - if I understand the
semantics of your smart pointer correctly, a common mistake would be
your_shared_ptr<std::string> p(new std::string("I will never be deleted!"));
While this too could be alleviated by forcing the use of different
initialization functions depending on the required semantics, the
unfortunate side-effect is that usage (IMHO) becomes less intuitive.
By the way, how is the reference counter shared between the owners when the
unadorned pointer walks alone?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk