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

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


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



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