why doesn't scoped_ptr have a custom deleter?
Hi, I'm currently playing around with Apache's Xerces XML library, and found myself needing to ->release some pointers. shared_ptr + mem_fn works great: shared_ptr<DOMBuilder> db( impl->createBuilder() , mem_fn(&DOMBuilder::release) ); But for the objects I'm using, I don't need a shared_ptr, but just a scoped_ptr. So I'm wondering about the rationale behind not giving scoped_ptr a custom deleter? Is it that shared_ptr's overhead is negligible (when not being shared I mean)? thanks
On Mon, 3 Jan 2005 14:29:43 -0800, Pablo Aguilar
Hi,
I'm currently playing around with Apache's Xerces XML library, and found myself needing to ->release some pointers. shared_ptr + mem_fn works great:
shared_ptr<DOMBuilder> db( impl->createBuilder() , mem_fn(&DOMBuilder::release) );
But for the objects I'm using, I don't need a shared_ptr, but just a scoped_ptr. So I'm wondering about the rationale behind not giving scoped_ptr a custom deleter? Is it that shared_ptr's overhead is negligible (when not being shared I mean)?
I noticed same omission just the other day when working with libxml2. I was forced to use shared_ptr when scoped_ptr would have made more sense (localized transfer-of-memory ownership with a custom deleter). I think it makes sense to add this to scoped_ptr, but perhaps the lack of support is a design decision (overhead?) -- Caleb Epstein caleb dot epstein at gmail dot com
Pablo Aguilar wrote:
Hi,
I'm currently playing around with Apache's Xerces XML library, and found myself needing to ->release some pointers. shared_ptr + mem_fn works great: shared_ptr<DOMBuilder> db( impl->createBuilder() , mem_fn(&DOMBuilder::release) );
But for the objects I'm using, I don't need a shared_ptr, but just a scoped_ptr. So I'm wondering about the rationale behind not giving scoped_ptr a custom deleter? Is it that shared_ptr's overhead is negligible (when not being shared I mean)?
No, it's that the overhead of a custom deleter (with state) is negligible in shared_ptr's case, but significant in scoped_ptr's case. You'd typically like to return this pointer from a factory function to avoid repeating the deleter part everywhere, too. scoped_ptr can't be returned.
Thanks
"Peter Dimov"
Pablo Aguilar wrote:
Hi,
I'm currently playing around with Apache's Xerces XML library, and found myself needing to ->release some pointers. shared_ptr + mem_fn works great: shared_ptr<DOMBuilder> db( impl->createBuilder() , mem_fn(&DOMBuilder::release) );
But for the objects I'm using, I don't need a shared_ptr, but just a scoped_ptr. So I'm wondering about the rationale behind not giving scoped_ptr a custom deleter? Is it that shared_ptr's overhead is negligible (when not being shared I mean)?
No, it's that the overhead of a custom deleter (with state) is negligible in shared_ptr's case, but significant in scoped_ptr's case. You'd typically like to return this pointer from a factory function to avoid repeating the deleter part everywhere, too. scoped_ptr can't be returned.
participants (3)
-
Caleb Epstein
-
Pablo Aguilar
-
Peter Dimov