Boost logo

Boost :

From: Kevlin Henney (Kevlin.Henney_at_[hidden])
Date: 1999-07-14 06:50:57

Yes, a ctor failure could be designed to result in a zombie (and if nocount
were also implemented, that would offer a possible route to a usable
zombie). However, this would imply that the user would have to explicitly
check the state of the object after construction to see whether it
succeeded or not (eg by calling use_count), which leads us right back to
the purpose of exceptions in simplifying such control flow!

The count of 1 could be introduced as a static and would be the initial
value for any given pointer. The only operations that could lead to failure
would be copying operations (ie cp ctor and op=), but in such cases failure
would not result in the loss of the held object, only the failure to share

   template<typename T>
   class shared_ptr
       explicit shared_ptr(T* p = 0) : px(p), pn(const_cast<long *>(&one))
       shared_ptr(const shared_ptr& r)
         : px(r.px), pn( == &one ? ( = new long(1)) : {
   ++*pn; }
       mutable long* pn;
       static const long one = 1; // initialised here for exposition only

With some refactoring of the count manipulation code in shared_ptr this
would be trivial to introduce.



Reid Sweatman <reids_at_[hidden]> on 13/07/99 18:45:47

Please respond to boost_at_[hidden]

To: "'boost_at_[hidden]'" <boost_at_[hidden]>
cc: (bcc: Kevlin Henney/QA Training Ltd)
Subject: [boost] Re: Misc library documentation issues

> However, returning to the point, the idea of adding a
> nocount is not
> really adding a new type of smart ptr at all. It simply allows more
> flexible use of the library. The introduction of a shared
> count for 1
> allows a simple optimisation for a common case, and a
> resolution of the
> construction problem (ctors would then never fail).

I agree with all your other points. However, couldn't a CTOR failure with
this mechanism result in a zombie?

Just Tell Us What You Want... - Shopping the World for You! home: - Simplifying group communications

------------------------------------------------------------------------ home: - Simplifying group communications

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