
Christopher Schmidt schrieb:
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
I think gcc is correct. There are two distinct instances of X in B, and those may not have the same address. That's why there is that 4 byte displacement. It is pretty much the same in Fusion. All inbuilt sequences and the vector data storage share a common base class - fusion::sequence_root - that's where the 4 resp. 8 bytes come from. -Christopher