Boost logo

Boost :

From: jon.jagger_at_[hidden]
Date: 1999-07-15 12:55:18


 <802567af.004a6514.0-_at_[hidden]> wrote:
original article:http://www.egroups.com/group/boost/?start=349
> > 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
> > it:
>
> Please explain the advantage of these semantics. Of course we could
make
> the
> change, but what's the point?
>
> 1. Exception behaviour occurs only for sharing, not for acquisition
> 2. The object that is being acquired is not jettisoned at the
first sign
> of trouble.

Number 2 is what draws me to Kevlins idea. At the moment shred_ptr has
a blanket assumption that delete p; is the correct thing to do. And of
course for the idiomatic use it is. But perhaps there is some merit in
viewing the decision about what to do if the resource acquisition fails
as being a client-side decision. For example...

        widget * p = new widget(...);
        shared_ptr<widget> sp(p);

If the bad_alloc exception comes out of the shared_ptr c'tor p will be
dangling. It's because new long(1) can throw an exception the
shared_ptr is _forced_ into assuming responsibility for doing the
delete and it is no longer a client side decision. I think Kevlin's
idea is useful because it allows us to revisit the question of
resource-acquisition and make it atomic and quaranteed.

Just my <$0.02 worth
JJ

------------------------------------------------------------------------

eGroups.com home: http://www.egroups.com/group/boost
http://www.egroups.com - Simplifying group communications


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk