This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Eigen and Qt and memory alignment

Tags: None
(comma "," separated)
MrFrankly
Registered Member
Posts
4
Karma
0

Eigen and Qt and memory alignment

Mon Jul 08, 2013 3:37 pm
Dear all,

It would be great if I can get some information regarding Eigen memory alignment (possibly in combination with Qt).

Code: Select all
class Test01
{
public:
    Eigen::Matrix<float, 4, 4> m_T;

    Test01() {}

    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

class Test02
{
public:
    Test01 bla2;

    Test02() {}

    //EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

class Test03 : public QObject
{
public:
    Test03() : QObject()
    {
        Test02* bla = new Test02;   
    }
    //EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

int main(int argc, char *argv[])
{   
    Test03 test;
    return 0;
}


The above code will give an memory alignment error.

The alignment error can be prevented by either uncommenting the EIGEN_MAKE_ALIGNED_OPERATOR_NEW in class Test02 or by removing the QObject inheritance on Test03. Clearly the latter is not an option, as I would like to use Qt methods on the class. The first option (setting EIGEN_MAKE_ALIGNED_OPERATOR_NEW on Test02) would be possible. However, it is unclear to me, from the Eigen documentation, if it is required to set EIGEN_MAKE_ALIGNED_OPERATOR_NEW on all classes that have a member that uses an aligned Eigen object.

In other words: if class Test02 has a member of class Test01, which in turn has a member that can be aligned (m_T) does Test02 also need a EIGEN_MAKE_ALIGNED_OPERATOR_NEW?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Yes you must have EIGEN_MAKE_ALIGNED_OPERATOR_NEW in the Test02 class, just like Test01 must have it. However, if Test02 would inherit Test01, then Test02 would not need EIGEN_MAKE_ALIGNED_OPERATOR_NEW.
MrFrankly
Registered Member
Posts
4
Karma
0
Thanks - clear answer. I think it would be very useful if the Eigen documentation mentions the requirement of having the EIGEN_MAKE_ALIGNED_OPERATOR_NEW macro also on all classes that indirectly (through composition, like Test02) have alignable Eigen members.

Also, I assume that the QObject inheritance on Test03 causing the memory alignment assertion to fail is pure coincidence?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
MrFrankly wrote:Also, I assume that the QObject inheritance on Test03 causing the memory alignment assertion to fail is pure coincidence?


yes, that's the only explanation making sense.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]