Boost logo

Boost :

From: Ulrich Eckhardt (doomster_at_[hidden])
Date: 2006-04-06 01:50:47 says:
"As a general rule, if it isn't obvious whether intrusive_ptr better
fits your needs than shared_ptr, try a shared_ptr-based design first."

I wonder why? Embedding the refcounter into the object seems to me much more
natural and performant than adding another free-store allocation which
shared_ptr requires.

Another related thing is why is there no complementary class to add a
refcounter to an object? Something like

template<typename ObjectType>
struct refcount
  refcount(): refs(0) {}
  refcount( refcount const&);
  refcount& operator=(refcount const&);

  friend void intrusive_ptr_add_ref( ObjectType* o) {
  void add_ref() {
  friend void intrusive_ptr_release( ObjectType* o) {
  void release() {
      delete static_cast<ObjectType*>(this);
  some-integer-type refs;

(I think that I can't legally inject functions into the surrounding namespace
via these friend functions, but maybe there's a workaround and this is just a
sketch. )


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