Re: [eigen] STL Vectors and Alignment |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
On 26.11.2014 16:17, Gabriel wrote:
So that means if we have a class S with a hierarchy of classes composed
By hierarchy of classes, I usually assume inheritance, not composed ones.
in each other and
the last one uses a fixed-size vectorizable type, for example
In your example, I would call `A` the first class/struct (or inner-most
to be more specific). Your code would not compile as it is, because `C`
needs to know `B` and `B` needs to know `A`.
struct C{
B a;
};
struct B{
EIGEN_MAKE_ALIGNED_OPERATOR_NEW // < IS THIS NEEDED? not really
A a;
};
struct A{
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Eigen::Vector2d a;
};
You need the EIGEN_MAKE_ALIGNED_OPERATOR_NEW only in classes which you
intend to allocate using new. It will not really hurt, adding it to all
other classes as well (only some code is generated, which should be
removed during linkage if it is not used).
Inheritance will propagate AlignedNew, but composing classes will not.
and we want to use S in an std::vector<S>
We need :
#include<Eigen/StdVector>
std::vector<S, Eigen::aligned_allocator<S> >;
Yes, if S requires alignment, this is what you need to write (for
C++03). C++11 makes the #include<Eigen/StdVector> redundant.
Is that correct? Isnt that really cumbersome? hm....
Mostly, that is the fault of C++, because it does not automatically
propagate alignment requirements to new and std::allocator. This does
not properly work in C++11 yet, either (not sure if by design, or
because compilers aren't ready yet).
Also cf this bug report:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53900
Actually, for many 64bit systems many things work out of the box,
because allocation methods align to 16byte by default (again, I'm not
entirely sure if that is mandatory, or system specific).
Christoph
--
----------------------------------------------
Dipl.-Inf., Dipl.-Math. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen
Tel: +49 (421) 218-64252
----------------------------------------------