Boost logo

Boost :

From: bill_kempf (williamkempf_at_[hidden])
Date: 2002-02-08 16:34:41


--- In boost_at_y..., Ruslan Zasukhin <sunshine_at_p...> wrote:
> Hi Bosters,
>
> Question to developers of auto_ptr<> in BOOST.
>
> Do you know that exists implementation of counter ptr,
> That is more effective that your auto_ptr<> ?

auto_ptr<> is std::auto_ptr<> and has little to do with Boost. I
assume you mean boost::shared_ptr<>.

> It is in CodeWarrior.
>
> Idea is split it on 2 classes
>
> Sharable { ulong refCount; }
> SharablePtr<t> { T* ptr_ }
>
> Usually we have
>
> 1 sharable object
> MANY pointers to it.
>
> Your auto_ptr<> has size 8 bytes: ptr and ptr to counter.
> So if we have 100 pointers around object, you use
>
> 4 -- counter
> 100 * 8 = 800 pointers.
>
> In above implementation
>
> 4 counter
> 100 * 4 = 400 bytes pointers.
>
> IF to think about passing of SharablePtr<t> to/from function,
> then it is effective 100% the same as normal C++ pointer. Wow.

But only works if you can modify the object type that will be pointed
to. This is covered in the documentation.

There's an infinite variety of smart pointers, and no one smart
pointer is better then another, it solely depends on your needs.
That's why there's interest in adding the Loki smart pointer to
Boost. Using policies, the Loki smart pointer allows for all of
these smart pointer varieties.
 
> And ... While I have type this letter it seems I have got idea!
>
> For now in Valentina I use auto_ptr<> in sense of your scope_ptr<>.
> And I have separate classes for Sharable and SharablePtr.
>
> BUT, may be it is possible make just specialization of auto_ptr<>
> In case it point on sub-classes of Sharable?
>
> template<>
> auto_ptr<Sharable*>
> {
> // for such pointer we use only 4 bytes:
> Sharable* ptr_;
> };
>
> What you think guys ?

Frankly, this last part just confuses me. You've now thrown in
scoped_ptr<>, which is a Boost smart pointer, leaving me to wonder
when you speak of auto_ptr<> do you mean std::auto_ptr<> or
boost::shared_ptr<>?

Bill Kempf


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk