|
Boost : |
From: Greg Colvin (gcolvin_at_[hidden])
Date: 2002-01-16 01:53:16
From: "Stewart, Robert" <stewart_at_[hidden]>
> > From: Peter Dimov [SMTP:pdimov_at_[hidden]]
> >
> > As for release(), I think that it needs to be dropped.
>
> I recently created a special-purpose smart pointer that releases the ref
> count of something relying on a C API. I wanted to write my functions that
> return such pointers to return smart pointer objects to ensure that the ref
> count was decreased even if I simply ignored the return value of such
> functions. However, when returning to the calling C API, I needed to turn
> over the raw pointer in the return value, relinquishing ownership of it. To
> do that, I call release() on my smart pointer class (which, based upon
> Andrei's insight, should be a non-member function).
>
> If I were using a Boost smart pointer without support for release(), how
> would I relinquish ownership()? That is, how do I tell the Boost smart
> pointer to not "deallocate" the pointer it holds, without release()?
If I understand you, then I don't see why you need release().
I imagine your code looks like this:
extern "C" T* entry_point(T* p) {
special_smart_ptr<T> wrapped_p(p);
do_stuff_with(wrapped_p);
assert(wrapped_p.unique());
return p;
}
If the assertion above fails then somewhere you have a copy
of wrapped_p that you shouldn't.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk