FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
February 01, 2004

Smart Pointers Reloaded (III): Construction

(Page 2 of 3)
February 04: Smart Pointers Reloaded (III): Construction Trackingsmart_ptr initialization

Listing 1: The original smart_ptr initialization mechanism.

ref_counted::ref_counted() {
   pCount_ = static_cast<unsigned int*>(
      SmallObject<>::operator new(sizeof(unsigned int)));
   assert(pCount_);
   *pCount_ = 1;
}

bool ref_counted::release(const P&) { if (!--*pCount_) { SmallObject<>::operator delete(pCount_, sizeof(unsigned int)); return true; } return false; }

class smart_ptr : public storage_policy<T> , public ownership_policy<typename storage_policy<T>::PointerType> , public checking_policy<typename storage_policy<T>::stored_type> , public conversion_policy { ... };

smart_ptr::smart_ptr(const stored_type& p) : SP(p) { KP::OnInit(GetImpl(*this)); }

smart_ptr::~smart_ptr() { if (OP::release(GetImpl(*static_cast<SP*>(this)))) { SP::Destroy(); } }

Previous Page | 1 | 2 | 3 Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK