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 >
Where are the extra 8 bytes going? With more complex boost::fusion objects I see an overhead of up to 16 bytes. gdb indicates that foo.data.vec has the desired size, but foo.data is larger, and foo is larger still; however, it doesn't indicate any data members --- is this some sort of alignment issue?
Is there a way to generate a "packed boost::fusion::map" without this space overhead?
R
#include <iostream>
#include "boost/fusion/container.hpp"
struct Name {};
int main() {
typedef boost::fusion::map > Foo;
struct FooS {
int age;
};
std::cout << "sizeof(Foo) = " << sizeof(Foo)
<< " sizeof(FooS) = " << sizeof(FooS)
<< std::endl;
}