Boost logo

Boost :

From: Nathan Myers (ncm_at_[hidden])
Date: 1998-12-07 15:08:00

Greg Colvin wrote:
> Nathan Myers wrote:
> > Beman Dawes writes:
> > > Greg has two implementations (with identical interfaces) of
> > > shared_ptr:
> >
> > ... I would choose the "direct" version.
> > Simple benchmarks are unlikely to distinguish the two, but
> > on a heavily-loaded system the indirect version is more
> > vulnerable to locality effects and to memory manager
> > fragmentation.
> Recall (as you may already) that both versions store the count on
> the heap:
> "direct": object <- shared_ptr -> count
> "indirect": shared_ptr -> count -> object
> You understand this stuff better than I do, but I don't really see how
> the "indirect" version suffers compared to the "direct", though it might
> depend a lot on the memory manager. Perhaps some decent memory managers
> would be a good addition to Boost.

True, I mis-reconstructed the direct case. I agree that the memory
allocator sees the two cases identically. Still, the direct case
should be less subject to locality effects simply because you only
use the "count" block during a copy or destruction, not during
normal (presumably much more frequent) use of the pointer. The
gain is probably worth the larger size of the shared_ptr object,
except on some embedded platforms.

I'm starting to think, why not parameterize it as Dietmar suggested?
It makes something easy for users to ignore if they prefer, or tune
if they like.

Nathan Myers

Free Web-based e-mail groups --

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