|
From: Christophe Prud'h. <pru...@MI...> - 2001-09-06 23:55:32
|
* Ian Crawford [Thursday 06 September 2001 10:45 am ] :
> Now, I'm completely unfamiliar with CoreLinux++, so I might be out o=
f
> line posting here. I apologize in advance if this is the case.
Not at all, the point of this list is to share ideas on analysis/design/i=
mplementation
The problem with smart pointers is that there are so many ways to do it =
and to use them.
IMHO depending on the type of application/usage, "different" policies sho=
uld/could be used
so when it comes to use smart pointers in multithreading codes, then the =
multithreaded version
would be used whereas the singlethreaded one would be used in general. Me=
mory management is also=20
a policy and can be done in several ways. Checking correctness/nonnullnes=
s is also a policy: whether you
want or not to check to validity of the pointee at any time.
In this respect the work of Andrei Alexandrescu(Modern C++ design publish=
ed by Addison Wesley ) is
very interesting and shows how smart pointers can be implemented using te=
mplates and policies.
Basically the smart pointer class look like this (excerpt from the book)
template
<
typename T,
template <class> class OwnershipPolicy =3D RefCounted,
class ConversionPolicy =3D DisallowConversion,
template <class> class CheckingPolicy =3D AssertCheck,
template <class> class StoragePolicy =3D DefaultSPStorage
>
class SmartPtr;
The various policies are orthogonal and can be changed easily. policies a=
re very small classes
which customized the behaviour of the SmartPtr.
I strongly suggest the reading of this book in general and the chapter on=
smart pointer in particular.
I was waiting Frank to come back and discuss about this design.
see ya
C.
--=20
Christophe Prud'homme=20
OOA and OOD for Linux
CoreLinux -- http://corelinux.sourceforge.net
Finite Element Method Codes
KFem -- http://kfem.sourceforge.net
|