Boost logo

Boost Users :

Subject: Re: [Boost-users] sizeof(boost::fusion:map)
From: Larry Evans (cppljevans_at_[hidden])
Date: 2010-11-06 08:55:47


On 11/06/10 07:33, alfC wrote:
[snip]
>
>
> On Nov 6, 5:17 am, Christopher Schmidt <mr.chr.schm..._at_[hidden]>
> wrote:
[snip]
>> Nothing is stored in those 4 additional bytes.
>> As I said above one additional byte is added by the compiler to the
>> 3*sizeof(double) bytes so one is able to distinguish between the two
>> instances of a common base class (fusion::sequence_root) of the vector
>> (fusion::vector<double, double, double>) and the internal vector data
>> storage (fusion::vector3<double, double, double>). To get size and
>> alignment right this one byte actually emits a 4-byte overhead on your
>> compiler.
>
> Isn't something called Empty Base Optimization that helps with this
> problem? (not sure if it applies here).
>
> So there is no way around it? (unless the internal design is changed?)
[snip]
Not if the compiler conforms to the standard, AFAICT.
However, apparently, according to the Christopher's earlier post:

  http://article.gmane.org/gmane.comp.lib.boost.user/63553

MSVC 2010 (x86) believes avoiding this restriction has some
advantage.

There is a link in this post:

  http://groups.google.com/group/comp.lang.c++/msg/ab0c802f7b5e9072

to comp.lang.c++ which maybe explains more. That post also
has a code attachment illustrating that EBO doesn't always
work as one might expect(see the struct empties_inherit).
The code attachment also shows a workaround using:

https://svn.boost.org/trac/boost/browser/sandbox/variadic_templates/boost/composite_storage/pack/container_all_of_aligned.hpp

HTH.
-Larry


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net