Boost logo

Boost :

From: brianjparker_at_[hidden]
Date: 2001-10-23 21:45:15

--- In boost_at_y..., "Fernando Cacciola" <fcacciola_at_g...> wrote:
> ----- Original Message -----
> From: <brianjparker_at_h...>
> To: <boost_at_y...>
> Sent: Saturday, October 20, 2001 9:17 PM
> Subject: [boost] Re: Several useful utility classes uploaded
> > --- In boost_at_y..., John Maddock <John_Maddock_at_c...> wrote:
> > >
> > > >alignment_traits class which is used to align stack-based or
> > static
> > > >memory
> > >
> > > See alignment_of in the type traits lib
> > >
> > >
> > > - John Maddock
> > >
> >
> > Hi,
> >
> > Yes, I am aware of alignment_of.
> > The problem is that just knowing the required alignment is not
> > without also having some form of standardised #pragma pack to
> > actually effect the alignment requirements.
> >
> > By contrast, alignment_traits<T>::align_t, being a POD, is
> > useable in a union to effect the alignment.
> >
> > For example, in the valunion class I use the following construct
> > align the embedded buffer
> >
> > union {
> > typename alignment_traits<A>::align_t al1;
> > typename alignment_traits<B>::align_t al2;
> > typename alignment_traits<C>::align_t al3;
> > char buffer[size_max];
> > };
> >
> > I don't see how this buffer could be aligned with
> > alignment_of<T>::value alone.
> >
> > I do think though that a good place to add the functionality of
> > aligment_traits<T>::align_t to Boost is in boost::alignment_of
> > boost::alignment_of could have an additional member align_t and
> > alignment_traits would then be hidden in a detail namespace.
> >
> > ,Brian Parker
> >
> >
> Please, take a look at: aligned_storage.hpp (and
> aligned_storage_detail.hpp) in
> I believe this is exactly the same that you are presenting here.
> Let me know what do you think.
> Regards,
> Fernando Cacciola
> Sierra s.r.l.
> fcacciola_at_g...

Yes, you have faced exactly the same alignment problem as I have; the
fact that at least two of us have had to solve the same problem is a
good existence proof for the need for this functionality to be
available in the language! (actually, as well as the stack_allocator,
hinted_node_allocator and valunion classes that I have submitted, I
have also needed this functionality in several other classes that I
have developed over the years).

The best solution, I think, given that the problem cannot be
completely solved in current ISO C++, would be a language change that
added a standardised alignment_of() and #pragma align that worked on
members of structures and in templated code.

Failing that, however, a second best solution is to have a standard
(or, initially, Boost) library class that could be guaranteed to work
on all tested platforms (using platform-specific implementations if

Your alignment_alias<T>::type appears to be a more sophisticated
implementation than my alignment_traits<T>::align_t and may do a
better job, assuming that boost::alignment_of<>::value is accurate
which it is not guaranteed to be.
(minor note: I see that your list of base types from which to choose
doesn't include a POD- I had the vague impression that some C++
implementations can give a structure a different alignment to
everything else, so it may be prudent to add one to your list).

My aligment_traits<T>::align_t class is more conservative and
optimised for small types- it may produce a larger alignment than
required. Maybe some tests are needed on different platforms to see
which approach works best.

In any case, I think that one of these classes or something like it
should be added to Boost.

Do you agree that boost::alignment_of<T>::align_t would be the best
way to integrate it into Boost?

,Brian Parker.


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