Re: [eigen] About alignement: two use cases

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


Hi,

sorry for the delay,


On Tue, Jan 18, 2011 at 3:33 PM,  <hamelin.philippe@xxxxxxx> wrote:
> USE CASE #1
> ===========================
>
> Let say I have a class looking like this:
>
> class A
> {
> public:
>
>     Eigen::Vector6d v;
>
>     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
> };
>
> So far, I think this is the right way to do it. However, if another
> class derive from it:
>
> class B : public A
> {
>     ...
> }
>
> Does the class B has also to use the EIGEN_MAMKE_ALIGNED_OPERATOR_NEW macro?

Unfortunately the answer is yes.


> USE CASE #2
> ===========================
>
> Let say I have a static library compiled with the EIGEN_DONT_ALIGN
> flash, which contains this class:
>
> class C
> {
> public:
>
>     Eigen::Vector6d v;
> }
>
> Then, if I use this class from another program that is NOT compiled with
> EIGEN_DONT_ALIGN, e.g.:
>
> int main(void)
> {
>     C* my_C = new C();
>
>     Eigen::Vector6d my_v = my_C.v;
>
>     return 0;
> }

The EIGEN_DONT_ALIGN flag breaks the ABI, so basically you should not
try to link a program compiled without this flags against a lib
compiled with it.

> In that case, the "v" member of class C is implicitly not aligned. However,
> the progam doesn't specify anything about alignement. Does this makes sense?
> Does the casting will be done correctly as in:
>
> Eigen::MAtrix<double, 6, 1, Eigen::DontAlign> v_unaligned;
> Eigen::MAtrix<double, 6, 1> v_aligned;
>
> v_aligned = v_unaligned;

The EIGEN_DONT_ALIGN flag does not work like that, in the sens that it
does not automagically transform all Matrix<> types to the equivalent
with the Eigen::DontAlign option.

btw, note that there also exist a EIGEN_DONT_ALIGN_STATICALLY flag
which only disable the alignment for static allocation (fixed size
objects).

gael

>
> Thank you,
>
> ------------------------------------
> Philippe Hamelin, ing. jr, M. Ing
> Chercheur / Researcher
>
> T: 450-652-8499 x2198
> F: 450-652-1316
>
> Expertise robotique et civil
> Institut de recherche d'Hydro-Québec (IREQ)
> 1740, boul. Lionel-Boulet
> Varennes (QC) J3X 1S1, Canada
>



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