Boost logo

Boost :

From: Gavin Collings (gcollings_at_[hidden])
Date: 2000-01-29 08:24:08

 2. and of course, using a circular list could cut down the code somewhat:
> if (left == this)
> delete ptr;
> left->right = right; // unlink
> right->left = left;
> ptr = pNewLeft->ptr; // adopt
> left = pNewLeft; // link
> right = pNewLeft->right;
> right->left = this;
> pNewLeft->right = this;
> I notice this has the advantage of containing more straight-line code than
> the current implementation does (one branch vs. two). I'd rather see a
> of the circular case ;)

I've already done these tests since my implementation uses a circular list
anyway. I've attached the implementation, the test code and a spreadsheet I
used to fit the results. (assignment boils down to what you have with a
minor mod to bypass unlinking code if you're not attached). I ran these
tests on Visual C++ 6 SP3 in Release mode. It may be useful to try some
other compilers.

In summary, sharing operations i.e. assignment / copy-cons run at about half
the speed of their shared_ptr counterparts. The real advantage comes from
avoiding the huge overhead of the heap allocation for the reference count in
shared_ptr. This worked out at about 2.9 microseconds for shared_ptr and
was indistinguishable from zero for linked_ptr.

Taking all of this into consideration, shared_ptr becomes more efficient at
above about 50 sharing operations - well beyond common usage I should


Gavin Collings

Boost list run by bdawes at, gregod at, cpdaniel at, john at