Boost logo

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

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:

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:
Sent from the Boost - Dev mailing list archive at

Boost list run by bdawes at, gregod at, cpdaniel at, john at