$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2005-11-20 06:56:39
Hi to all,
While developing Shmem I wrote a smart pointer to represent relative
pointers and now I'm experimenting with a multi-segment shared memory
pointer to create growing multi-segment shared memory containers and
allocators. Both pointers are based on boost smart pointer's interface
(shared_ptr, etc...).
In Shmem and possibly other generic libraries the developer wants
pointer-independent code, so that the pointer type is a template
parameter and the same code is used for relative, reference counted,
intrusive, raw, or multisegment pointers. One of such uses, in Shmem, is
for example, a memory allocator (a first fit, best fit algorithm) or an
intrusive container. While developing pointer-independent code, however,
I've seen that some features are present in boost (for example,
get_pointer() function) and other features are missing, and I would like
to propose them:
1. Overloads of static_pointer_cast, dynamic_pointer_cast,
const_pointer_cast overloads for raw pointers, so that we can use
pointer_xxx_cast in a generic way.
2. Add reinterpret_pointer_cast to complete cast family.
3. A protocol to obtain a pointer of the same type from any pointer. For
example, if you want to generically use a pointer (for example, raw or
relative pointer) in a class and you want to declare another pointer to
other type (raw or relative, depending on the source):
//typedef typename boost::pointer_to_other
//<GenericPointer, NewType>::type MyNewPointer;
//A new pointer to float values
typedef typename boost::pointer_to_other
<SmartPtr, float>::type MyFloatPointer;
We should define how this protocol is implemented in boost smart
pointers (for example, using overloading or a STL-like rebind mechanism)
so that every boost smart pointer developer knows how to make its
pointer type protocol-aware. Shmem uses rebind-like mechanism now, but
the mechanism is not important. This way, a class can receive a void
pointer like a template parameter and can be pointer-independent:
template <class VoidPtr>
class memory_manager
{
struct memory_block
{
//...
};
typedef typename boost::pointer_to_other
<VoidPtr, memory_block>::type BlockPtr;
BlockPtr mp_free_list;
};
I think these utilities are simple to develop and quite useful. What do
smart pointer experts think?
Regards,
Ion