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

unaligned arrays assert if child class contain eigen objects

Tags: None
(comma "," separated)
jakster
Registered Member
Posts
3
Karma
0
OS
I've a class foo containing a class bar

Code: Select all
class foo {
private:
    bar _bar;
public :
 foo() :
    bar()
{}
}


Code: Select all
class bar {
private:
   Eigen::Matrix<....> fixedSizeMatrix;
public:
   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
   bar(){}
}


foo is instantiated with

Code: Select all
foo* fooVar = new foo();


This crashes with the error described here http://eigen.tuxfamily.org/dox/UnalignedArrayAssert.html. Adding EIGEN_MAKE_ALIGNED_OPERATOR_NEW
to foo fixes this problem.

The question is, does EIGEN_MAKE_ALIGNED_OPERATOR_NEW have to specified for all classes that contain classes (that contain classes etc) that contain Eigen types? We tend not to use the new keyword but instantiate classes directly.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
The question is, does EIGEN_MAKE_ALIGNED_OPERATOR_NEW have to specified for all classes that contain classes (that contain classes etc) that contain Eigen types? We tend not to use the new keyword but instantiate classes directly.


Yes. This is really just a C++ issue: when class A has a data member of type B, just because B::operator new is overloaded doesn't do anything to A::operator new. So in order for 'new A' to work, you really need to overload A's operator new.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
jakster
Registered Member
Posts
3
Karma
0
OS
bjacob wrote:Yes. This is really just a C++ issue: when class A has a data member of type B, just because B::operator new is overloaded doesn't do anything to A::operator new. So in order for 'new A' to work, you really need to overload A's operator new.


Do we also need to overload class bar's new operator in this example? And is there a drawback of specifying EIGEN_MAKE_ALIGNED_OPERATOR_NEW when it is not necessary (for example, in a class never created using new or with no Eigen members)?
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Do we also need to overload class bar's new operator in this example?


Only if you want to do 'new bar'.

And is there a drawback of specifying EIGEN_MAKE_ALIGNED_OPERATOR_NEW when it is not necessary (for example, in a class never created using new or with no Eigen members)?


There's no significant drawback that I can see. Aligned memory allocation can be a bit slower (during the allocation itself), but that's it.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], q.ignora