www.digitalmars.com         C & C++   DMDScript  

c++.stlsoft - Smart pointers, RAII and custom deleters

reply "Adi Shavit" <adish gentech.co.il> writes:
Hi,


Though not exactly related to STLSoft (yet?) I'm posting this here after
posting it to c++mod, maybe you'll have some insights for me.

  I frequently find myself having to use C based APIs to allocate and
deallocated resources. Using these APIs requires remembering to
deallocate all the resources through special deallocation functions
(not to mention exception safety). I would really like a general
"smart pointer/resource" or raii_ptr<> class that I can access as a
regular pointer and that accepts a custom deallocator.

Though boost::shared_ptr might suffice, it seems to convay the wrong
message since these resources are generally noncopyable nor sharable.
All I really need is scope_ptr with a custom deleter.


I was wondering why boost::scoped_ptr does not support custom
deleters. Is there a rational behind this?


In this article (http://www.artima.com/cppsource/bigtwo3.html#refs),
Bjorn Karlsson and Matthew Wilson propose such a hypothetical RAII
class for demonstration purposes. Does anyone know of a more
production-level implementation of such an idea?


Thanks,
Adi
Nov 10 2004
parent reply "Pablo Aguilar" <paguilarg hotmail.com> writes:
I asked something along these lines some time ago here...

I remember two things:
1) Loki's SmartPtr has a StoragePolicy, which, when customized allows you to 
also cutomize the deallocation process
2) Matthew said he'd do his lightweight compiler-friendly version some time 
in the future though he's always lacking time...

Someone else said he'd come up with a quick way to do it using Loki's 
SmartPtr, though I can't seem to find the post in the newsgroup, sorry...


"Adi Shavit" <adish gentech.co.il> wrote in message 
news:cmtsrp$1cm$1 digitaldaemon.com...
 Hi,


 Though not exactly related to STLSoft (yet?) I'm posting this here after
 posting it to c++mod, maybe you'll have some insights for me.

  I frequently find myself having to use C based APIs to allocate and
 deallocated resources. Using these APIs requires remembering to
 deallocate all the resources through special deallocation functions
 (not to mention exception safety). I would really like a general
 "smart pointer/resource" or raii_ptr<> class that I can access as a
 regular pointer and that accepts a custom deallocator.

 Though boost::shared_ptr might suffice, it seems to convay the wrong
 message since these resources are generally noncopyable nor sharable.
 All I really need is scope_ptr with a custom deleter.


 I was wondering why boost::scoped_ptr does not support custom
 deleters. Is there a rational behind this?


 In this article (http://www.artima.com/cppsource/bigtwo3.html#refs),
 Bjorn Karlsson and Matthew Wilson propose such a hypothetical RAII
 class for demonstration purposes. Does anyone know of a more
 production-level implementation of such an idea?


 Thanks,
 Adi

Nov 10 2004
parent reply "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
Mind readers!!

Only last night I was using my raii class (in the as yet unreleased
stlsoft/raii.hpp file), and pondering the really nicest way to do these
things. The one I've curerntly got is not very pretty (hence the fact
that I've not shared it with the world as yet).

FYI: I'm currently working 14hrs a day for my current client - who'd
have thought real work could be so hard after spending two years writing
a book! ;)  - but as soon as that's over in about 3 weeks I'll be
catching up on many things for a couple of months, including this and
other STLSoft issues

Bjorn's got the flu at the moment, but I'll send him a heartless email
telling him to start thinking about this stuff while he whiles away the
hours feeling sorry for himself. :-)

Cheers

Matthew


"Pablo Aguilar" <paguilarg hotmail.com> wrote in message
news:cmu0hb$6ca$1 digitaldaemon.com...
 I asked something along these lines some time ago here...

 I remember two things:
 1) Loki's SmartPtr has a StoragePolicy, which, when customized allows

 also cutomize the deallocation process
 2) Matthew said he'd do his lightweight compiler-friendly version some

 in the future though he's always lacking time...

 Someone else said he'd come up with a quick way to do it using Loki's
 SmartPtr, though I can't seem to find the post in the newsgroup,

 "Adi Shavit" <adish gentech.co.il> wrote in message
 news:cmtsrp$1cm$1 digitaldaemon.com...
 Hi,


 Though not exactly related to STLSoft (yet?) I'm posting this here


 posting it to c++mod, maybe you'll have some insights for me.

  I frequently find myself having to use C based APIs to allocate and
 deallocated resources. Using these APIs requires remembering to
 deallocate all the resources through special deallocation functions
 (not to mention exception safety). I would really like a general
 "smart pointer/resource" or raii_ptr<> class that I can access as a
 regular pointer and that accepts a custom deallocator.

 Though boost::shared_ptr might suffice, it seems to convay the wrong
 message since these resources are generally noncopyable nor


 All I really need is scope_ptr with a custom deleter.


 I was wondering why boost::scoped_ptr does not support custom
 deleters. Is there a rational behind this?


 In this article (http://www.artima.com/cppsource/bigtwo3.html#refs),
 Bjorn Karlsson and Matthew Wilson propose such a hypothetical RAII
 class for demonstration purposes. Does anyone know of a more
 production-level implementation of such an idea?


 Thanks,
 Adi


Nov 10 2004
parent reply "Matthew" <admin.hat stlsoft.dot.org> writes:
Just to let you know, I've got this sorted and it'll be out in 1.8.3 (which I
hope to release within the next 
fortnight).

FYI: Bjorn Karlsson and I are planning a mini series on smart pointers in our
Smart Pointers column (for The C++ 
Source), and there are going to be quite a few new (or revamped) smart pointers
appearing in STLSoft soon as a 
consequence.



"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message
news:cmv2rg$1ka4$1 digitaldaemon.com...
 Mind readers!!

 Only last night I was using my raii class (in the as yet unreleased
 stlsoft/raii.hpp file), and pondering the really nicest way to do these
 things. The one I've curerntly got is not very pretty (hence the fact
 that I've not shared it with the world as yet).

 FYI: I'm currently working 14hrs a day for my current client - who'd
 have thought real work could be so hard after spending two years writing
 a book! ;)  - but as soon as that's over in about 3 weeks I'll be
 catching up on many things for a couple of months, including this and
 other STLSoft issues

 Bjorn's got the flu at the moment, but I'll send him a heartless email
 telling him to start thinking about this stuff while he whiles away the
 hours feeling sorry for himself. :-)

 Cheers

 Matthew


 "Pablo Aguilar" <paguilarg hotmail.com> wrote in message
 news:cmu0hb$6ca$1 digitaldaemon.com...
 I asked something along these lines some time ago here...

 I remember two things:
 1) Loki's SmartPtr has a StoragePolicy, which, when customized allows

 also cutomize the deallocation process
 2) Matthew said he'd do his lightweight compiler-friendly version some

 in the future though he's always lacking time...

 Someone else said he'd come up with a quick way to do it using Loki's
 SmartPtr, though I can't seem to find the post in the newsgroup,

 "Adi Shavit" <adish gentech.co.il> wrote in message
 news:cmtsrp$1cm$1 digitaldaemon.com...
 Hi,


 Though not exactly related to STLSoft (yet?) I'm posting this here


 posting it to c++mod, maybe you'll have some insights for me.

  I frequently find myself having to use C based APIs to allocate and
 deallocated resources. Using these APIs requires remembering to
 deallocate all the resources through special deallocation functions
 (not to mention exception safety). I would really like a general
 "smart pointer/resource" or raii_ptr<> class that I can access as a
 regular pointer and that accepts a custom deallocator.

 Though boost::shared_ptr might suffice, it seems to convay the wrong
 message since these resources are generally noncopyable nor


 All I really need is scope_ptr with a custom deleter.


 I was wondering why boost::scoped_ptr does not support custom
 deleters. Is there a rational behind this?


 In this article (http://www.artima.com/cppsource/bigtwo3.html#refs),
 Bjorn Karlsson and Matthew Wilson propose such a hypothetical RAII
 class for demonstration purposes. Does anyone know of a more
 production-level implementation of such an idea?


 Thanks,
 Adi



Dec 14 2004
parent "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
This is now available in 1.8.3 beta 1. It's scoped_handle, in 
inprogress/stlsoft/scoped_handle.hpp

Please consult the release notes about the directory structure / 
dependencies stuff

"Matthew" <admin.hat stlsoft.dot.org> wrote in message 
news:cpmfi2$1agd$1 digitaldaemon.com...
 Just to let you know, I've got this sorted and it'll be out in 1.8.3 
 (which I hope to release within the next fortnight).

 FYI: Bjorn Karlsson and I are planning a mini series on smart pointers 
 in our Smart Pointers column (for The C++ Source), and there are going 
 to be quite a few new (or revamped) smart pointers appearing in 
 STLSoft soon as a consequence.



 "Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message 
 news:cmv2rg$1ka4$1 digitaldaemon.com...
 Mind readers!!

 Only last night I was using my raii class (in the as yet unreleased
 stlsoft/raii.hpp file), and pondering the really nicest way to do 
 these
 things. The one I've curerntly got is not very pretty (hence the fact
 that I've not shared it with the world as yet).

 FYI: I'm currently working 14hrs a day for my current client - who'd
 have thought real work could be so hard after spending two years 
 writing
 a book! ;)  - but as soon as that's over in about 3 weeks I'll be
 catching up on many things for a couple of months, including this and
 other STLSoft issues

 Bjorn's got the flu at the moment, but I'll send him a heartless 
 email
 telling him to start thinking about this stuff while he whiles away 
 the
 hours feeling sorry for himself. :-)

 Cheers

 Matthew


 "Pablo Aguilar" <paguilarg hotmail.com> wrote in message
 news:cmu0hb$6ca$1 digitaldaemon.com...
 I asked something along these lines some time ago here...

 I remember two things:
 1) Loki's SmartPtr has a StoragePolicy, which, when customized 
 allows

 also cutomize the deallocation process
 2) Matthew said he'd do his lightweight compiler-friendly version 
 some

 in the future though he's always lacking time...

 Someone else said he'd come up with a quick way to do it using 
 Loki's
 SmartPtr, though I can't seem to find the post in the newsgroup,

 "Adi Shavit" <adish gentech.co.il> wrote in message
 news:cmtsrp$1cm$1 digitaldaemon.com...
 Hi,


 Though not exactly related to STLSoft (yet?) I'm posting this here


 posting it to c++mod, maybe you'll have some insights for me.

  I frequently find myself having to use C based APIs to allocate 
 and
 deallocated resources. Using these APIs requires remembering to
 deallocate all the resources through special deallocation 
 functions
 (not to mention exception safety). I would really like a general
 "smart pointer/resource" or raii_ptr<> class that I can access as 
 a
 regular pointer and that accepts a custom deallocator.

 Though boost::shared_ptr might suffice, it seems to convay the 
 wrong
 message since these resources are generally noncopyable nor


 All I really need is scope_ptr with a custom deleter.


 I was wondering why boost::scoped_ptr does not support custom
 deleters. Is there a rational behind this?


 In this article 
 (http://www.artima.com/cppsource/bigtwo3.html#refs),
 Bjorn Karlsson and Matthew Wilson propose such a hypothetical RAII
 class for demonstration purposes. Does anyone know of a more
 production-level implementation of such an idea?


 Thanks,
 Adi




Mar 01 2005