Boost logo

Boost :

From: Ruslan Zasukhin (sunshine_at_[hidden])
Date: 2002-02-08 17:27:01


on 2/8/02 23:34, bill_kempf at williamkempf_at_[hidden] wrote:

Hi Bill,

>> 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<>.

yes

>> 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.

Yes, only if I can modify classes.
But in my work, I develop big project and have hundreds classes that can fit
into this.

> 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.

Excuse me, I am new to this list.
What is Loki smart pointer ?

>> 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<>?

Yes, I mean boost:: shared_ptr<>.

Don't you think that it is possible to write

A) general template AS IS

B) specialization for
    template<>
    shared_ptr<Sharable*>

Which will use second class sharable that keep counter ?

-- 
Best regards,
Ruslan Zasukhin
-------------------------
Paradigma.
e-mail: ruslan_at_[hidden]
web   : http://www.paradigmasoft.com
To subscribe to the Valentina mail list
send a letter to valentina-on_at_[hidden]

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