[Xapian-devel] Re: [Xapian-commits] 8107: trunk/xapian-core/
trunk/xapian-core/backends/
Olly Betts
olly at survex.com
Thu Apr 5 14:13:08 BST 2007
On Thu, Apr 05, 2007 at 12:51:50PM +0100, Richard Boulton wrote:
> Olly Betts wrote:
> >Yeah, that's reasonable enough. Perhaps we should profile AutoPtr vs
> >RefCntPtr to see if one of them is better for such situations - I've
> >wondered before.
>
> I thought that AutoPtr wasn't appropriate for this kind of thing - as
> soon as you get the pointer out of it, the AutoPtr doesn't care about
> deleting it any more.
But in cases like this where we only call methods on the pointer and
that's not an issue.
> Also, this doesn't happen in this case, but if a function which we'd
> passed the LeafPostList pointer to had created a new object which had a
> reference to our postlist, we wouldn't want to delete the LeafPostList
> at the end of our function - unreffing it is the right thing to do.
Again, that's not an issue in this situation because we're not passing
the pointer.
> So, I say it's safest to stick to using RefCntPtr in this kind of
> situation, so we don't have to think hard about whether to do so or not.
This is true - it makes the code more robust to copying and pasting,
though I think you'd need to add a call AutoPtr<>::get() which should
tip you off. Potentially the called class could do evil things with
"this" too.
I guess any efficiency difference will be pretty small too.
Cheers,
Olly
More information about the Xapian-devel
mailing list