Boost logo

Boost :

Subject: Re: [boost] intrusive_ptr design question
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-07-06 11:50:59


Zachary Turner wrote:
> On Mon, Jul 6, 2009 at 10:32 AM, Stewart,
> Robert<Robert.Stewart_at_[hidden]> wrote:
> > Zachary Turner wrote:
> >>
> >> Ok, so let me rephrase then: Is there a case to be made for
> >> a more flexible shared_ptr (either through modification or
> >> through a new class addition) that allows one to provide
> >> custom reference counting semantics much the same way that
> >> shared_ptr allows one to provide custom deletion semantics?
> >
> > I haven't followed your discussion closely, so I may have the
> > wrong idea, but don't you run the risk of mixing the
> > different ref counting techniques on objects of the same
> > type? If the ref counting scheme isn't part of the smart
> > pointer type, then all instances must do ref counting the
> > same way.
>
> That's correct. The way I have envisioned is analagous to the
> way shared_ptr allows you to specify a custom deleter.
> Whenever a copy is made, the new copy gets the same deleter.
> That way all copies agree on the deletion semantics. As long
> as all copies of the shared pointer that refer to the same
> underlying instance of pointed-to object agree on reference
> counting semantics, everything should be ok right?

Deleting with the wrong deleter is an obvious failure which is likely to crash an application, but only happens once per object. Manipulating a reference count, tens, hundreds, or more times, exposes a much greater danger. Yes, copies will agree on how to manipulate the reference count, but the same memory can be referenced by separately constructed, non-copied smart pointer instances.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


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