Why scoped_ptr dost provide custom deallocation?
As following manner: template<class D> scoped_ptr(Y * p, D d); Any suggestion are appreciated. -- /*******************/ ×ÔÓÉ£šliberty£©ÎÞ·ÇŸÍÊÇÕâÑùÒ»ÖÖ³Ðŵ£ºÃ¿žöÈËœ«»áµÃµœÒ»ÖÖ±£ÕÏ£¬±£ÕÏÎÒÃÇ¿ÉÒÔÓë ÈšÍþ¡¢¶àÊý¡¢Á÷Ë׌°ÓßÂÛµÄÓ°ÏìÏ࿹ºâ¡£ /*******************/
From: "Black Ice"
As following manner: template<class D> scoped_ptr(Y * p, D d);
Any suggestion are appreciated.
Scoped_ptr is intentionally kept as simple as possible to minimize overhead. A custom deallocation feature as above would require either doubling its size or making its operator* perform a double indirection. If you need the custom deallocator feature, use shared_ptr.
thanks.
--
/*******************/
×ÔÓÉ£šliberty£©ÎÞ·ÇŸÍÊÇÕâÑùÒ»ÖÖ³Ðŵ£ºÃ¿žöÈËœ«»áµÃµœÒ»ÖÖ±£ÕÏ£¬±£ÕÏÎÒÃÇ¿ÉÒÔÓë
ÈšÍþ¡¢¶àÊý¡¢Á÷Ë׌°ÓßÂÛµÄÓ°ÏìÏ࿹ºâ¡£
/*******************/
"Peter Dimov"
From: "Black Ice"
As following manner: template<class D> scoped_ptr(Y * p, D d);
Any suggestion are appreciated.
Scoped_ptr is intentionally kept as simple as possible to minimize overhead. A custom deallocation feature as above would require either doubling its size or making its operator* perform a double indirection.
If you need the custom deallocator feature, use shared_ptr.
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
And what if you use the deallocator as a template parameter?
+ It does not cost extra space
+ Don't need to use an extra reference-counted pointer
- The interface is not consistent with shared_ptr
How about that? I would be happy to see this advancement in the
scoped_ptr class.
Anyway: Do you know any smart-pointer class, which supports custom
deallocator and can transfer ownership? (auto_ptr does not support
custom deallocator and either smart_ptr or shared_ptr does not support
release() method).
--- In Boost-Users@yahoogroups.com, "Peter Dimov"
From: "Black Ice"
As following manner: template<class D> scoped_ptr(Y * p, D d);
Any suggestion are appreciated.
Scoped_ptr is intentionally kept as simple as possible to minimize overhead. A custom deallocation feature as above would require either doubling its size or making its operator* perform a double indirection.
If you need the custom deallocator feature, use shared_ptr.
Anyway: Do you know any smart-pointer class, which supports custom deallocator and can transfer ownership? (auto_ptr does not support custom deallocator and either smart_ptr or shared_ptr does not support release() method).
To a certain degree auto_ptr<YourClass> supports a custom de-allocator...overload operator delete in a known case for a specific object. I haven't actually done it, but it seems not too challenging to template a base class that does this for you with your custom allocator and then use it as a mix-in class for whatever class you are creating. Does that solve your issue or am I missing your point? If so, sorry I came a little late to this thread. michael
To a certain degree auto_ptr<YourClass> supports a custom de-allocator...overload operator delete in a known case for a specific object. I haven't actually done it, but it seems not too challenging to template a base class that does this for you with your custom allocator and then use it as a mix-in class for whatever class you are creating. Does that solve your issue or am I missing your point? If so, sorry I came a little late to this thread.
Not exactly: I cannot subclass the object which I want to use (DOMWriter from the Xerces lib), because it has hidden constructors. So the question still remains remains about theauto_ptr custom deallocator...
dlux42
And what if you use the deallocator as a template parameter?
+ It does not cost extra space + Don't need to use an extra reference-counted pointer - The interface is not consistent with shared_ptr
How about that? I would be happy to see this advancement in the scoped_ptr class.
The main reason that scoped_ptr doesn't provide this feature is that nobody
made a convincing case for it.
(An example of a convincing case: "In my project I have encountered the
following situation:
Anyway: Do you know any smart-pointer class, which supports custom deallocator and can transfer ownership? (auto_ptr does not support custom deallocator and either smart_ptr or shared_ptr does not support release() method).
No. auto_ptr
The main reason that scoped_ptr doesn't provide this feature is that nobody made a convincing case for it.
(An example of a convincing case: "In my project I have encountered the following situation:
and I believe that scoped_ptr would be a perfect fit." Some non-examples: "Someone might find it useful." "Wouldn't it be cool if...") I suspect that most people just use editor inheritance or specialize ~scoped_ptr.
I am now working on a project, where I use scoped_ptr and shared_ptr.
shared_ptr works well on most tasks, but I often need to instantiate
Xerces classes, which are used only locally, and must be release()-d
at the end of the procedure.
I wrote a custom_auto_ptr
No. auto_ptr
would indeed be useful, but many compilers can't handle the machinery that is needed to build an auto_ptr, which is probably why there are few auto_ptr reimplementations and enhancements around.
Hmmm. shared_ptr and scoped_ptr (and my custom_auto_ptr) work flawlessly on HP-UX aCC. Do you know a compiler which is even more worse than that? :-)
participants (4)
-
Black Ice
-
dlux42 <dlux@spam.sch.bme.hu>
-
Michael Hunley
-
Peter Dimov