|
Boost : |
Subject: Re: [boost] [interprocess] preparing containers
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2008-12-02 17:46:17
Ion Gaztañaga wrote:
>
> Thorsten Ottosen wrote:
>> What do we need to do to make a container that support the special
>> allocators?
>
> [...]
> JoaquÃn has successfully changed multiindex code to support Interprocess
> so maybe he knows better than anyone what's the best way to make an
> existing container compatible with Interprocess.
>
My adaptation process allows for special allocators to have the
following relaxations with respect to the standard (which
implicitly includes allocators from Boost.Interprocess):
"For every type T, the type Allocator::rebind<T>::other::pointer can be
any kind of Random Access Iterator, provided that it is explicitly
constructible from the literal 0 (standing here as the null pointer) or from
any p of type T* pointing into an area allocated by some instance of
Allocator or some other allocator type rebound from Allocator. A pointer
constructed from p shall dereference to *p."
The former allows us to apply the following idiom:
Allocator::rebind<T>::other::pointer p1=...;
T* p2=&*p1;
p2 and p1 point to the same T object and in general are interchangeable
(I can construct an Allocator::rebind<T>::other::pointer from a T*).
This leads to a particularly simple rule when adapting a container
to these special allocators:
Replace a T* p with a Allocator::rebind<T>::other::pointer
*only if* p is a non-local variable. Otherwise (i.e. p is a local
or automatic variable) just leave it like that and use the p2=&*p1
idiom if necessary.
The rationale is that local pointers won't ever live in shared memory
so it's not necessary to have them replaced by special pointes. This
makes the adaptation process a little simpler. This process can
be summarized as:
1. Replace (for adaptation purposes) your good old standard
allocator with a special allocator such as that in
https://svn.boost.org/trac/boost/browser/trunk/libs/multi_index/test/non_std_allocator.hpp
This will result in lots of compilation errors.
2. Look for all persistent (non-local) variables of type T* and
re-type to Allocator::rebind<T>::other::pointer. This
will result in further compilation errors due to the impedance
between Allocator::rebind<T>::other::pointer's and the
remaining T *'s.
3. Locate the points of impedance mismatch referred to
above and adapt using the p2=&*p1 idiom.
The whole process for Boost.MultiIndex is contained at
the changeset:
https://svn.boost.org/trac/boost/changeset/39922/
Alas the changeset includes other modifications not related
to this, but I think it can give you an idea. Hope this
helps a little.
JoaquÃn M López Muñoz
Telefónica, Investigación y Desarrollo
-- View this message in context: http://www.nabble.com/-interprocess--preparing-containers-tp20794468p20802770.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk