Boost logo

Boost :

From: svanechel_at_[hidden]
Date: 2001-06-11 13:34:33


Hi,

Recently I grew tired always having to write the same boiler plate
code when I wanted to manage a resource using the "resource
acquisition is initialization" technique. Looking for a more
generic
solution I browsed through the posted message and noticed that I
wasn't the first one who encountered this problem (yeah duh). At
a
first glance I couldn't find any acceptable solution (browsed
through
a large subset of the 13000+ postings), so I went on and tried it
myself. The solution I came up with uses a traits class to handle
both resource destruction and a suitable nul-value. I've uploaded
the
results in the files section (resource.zip).

Basically the RAII-harness (apparently that's the terminology for
it)
does most of the work and only those aspects that of resource
management that are dependent on the resource type are moved out into
a traits class. To test my idea I went on and (naively) re-
implemented the boost smart pointer classes <boost/smart_ptr.hpp>
using the classes I just created. I discern three different types:

* the non-copyable resources (boost::scoped_ptr and
boost::scoped_array)
* the shared resources (boost::shared_ptr and boost::shared_array)
* resources that aren't shared but can be copied (E.g. Win32
HANDLE
values)

Three base classes handle these three cases.

I would very much appreciate some input on the issue (is this
approach OK? Is the solution useful enough to be turned into a
library?)

Thanks,

Svenne


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk