Boost logo

Boost Users :

Subject: Re: [Boost-users] sizeof(boost::fusion:map)
From: Christopher Schmidt (mr.chr.schmidt_at_[hidden])
Date: 2010-11-05 19:32:18


Robert Lupton the Good schrieb:
> I was very excited to find the boost::fusion library, expecting that I could use it to implement structs with introspection. I still think I can, but I was disappointed to see that I'm paying a size penalty. I'd have expected all the book-keeping to be handled at compile time.
>
> The following code prints
> sizeof(Foo) = 12 sizeof(FooS) = 4
> with g++ 4.2 or 4.4 on an os/x 10.6 or Centos box.
>
> Here Foo is
> boost::fusion::map<boost::fusion::pair<Name, int> >
>
[snip]

I have no idea why there is that space overhead. This problem is not
fusion specific, though.

#include <iostream>
struct X{};
struct A:X{int i;};
struct B:X{A a;};
int main()
{std::cout << sizeof(A) << " " << sizeof(B) << std::endl;}

When compiled with gcc 4.5.1 i686-pc-mingw32 and -O2, the output is "4
8". When compiled with MSVC 2010 (x86) and /O2, "4 4" is printed.

-Christopher


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