Re: [eigen] Eigen2, G++ and sizeof()

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi,

Thanks for your mail. I tried with g++ 4.2.3 and got the same result.

You really found a bug in Eigen: I made the wrong assumption that empty 
members in a class didn't increase the sizeof().

Apparently this is a classical issue and there are several known workarounds:
http://www.google.com/search?q=c%2B%2B+sizeof+empty+class

I do not have time right now to look deeper into this issue but I will do it 
as soon as I get back to coding (which is not before in one month). Or, if 
you are interested in doing it yourself, I am always happy to receive 
patches. A good solution should provide optimal sizeof() in all cases, 
without obfuscating the source code too much.

Cheers,

Benoit


On Saturday 26 January 2008 21:17:21 Andri Möll wrote:
> Morning,
>
> I was just reviewing Eigen2 and discovered that for some reason GCC's g++
> lists Eigen's matrices a bit larger than they were meant to be.
> That is, 16 bytes for Vector3f unpacked, and 14 bytes when packed with
> #pragma pack(1).
>
> #include <iostream>
> #include "eigen2/Eigen/Core"
> int main(void)
> {
>         Eigen::Vector3f v;
>         std::cerr << "sizeof(v) = " << sizeof(v) << std::endl;
>         std::cerr << "v.size() = " << v.size() << std::endl;
> }
>
> $ g++ -Wall test.cpp && ./a.out
> sizeof(eigen) = 16
> eigen.size() = 3
>
> My disassembling skills under Unix-like OSes are a bit lacking, but a
> simple 'info gcc' and removal of some code helped identify the cause, which
> seems to be the templated value holding class you're using. GCC's manual
> says that empty classes end up with a "virtual" char, so that explains why
> temporarily removing dynamic matrix support and substituting it with enums
> makes the data usage Eigen1-like.
>
> I'm using Gentoo's stable GCC (4.1.2) and rev 766861 of Eigen2.
>
> I haven't tried the 4.2.x branch of GCC, does that have the same behavior?
>
>
> Andri


Attachment: signature.asc
Description: This is a digitally signed message part.



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/