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" <yg-boost-users@gmane.org>
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" <pdimov@mmltd.net> ÐŽÈëÏûÏ¢ÐÂÎÅ :002f01c2b81b$0841e840$1d00a8c0@pdimov2...
From: "Black Ice" <yg-boost-users@gmane.org>
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" <pdimov@m...> wrote:
From: "Black Ice" <yg-boost-users@g...>
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 <dlux@spam.sch.bme.hu> wrote:
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: <description with real(istic sounding) identifiers> and I believe that scoped_ptr<X, D> 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.
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<X, D> 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.
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: <description with real(istic sounding) identifiers> and I believe that scoped_ptr<X, D> 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<X, D> class for only this reason, but I think scoped_ptr<X, D> would be the perfect solution for it. (I use custom_auto_ptr, not custom_scoped_ptr, because these are basically the same, except the release(), method, which could be useful in the future).
No. auto_ptr<X, D> 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