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

Mapping Aligned Data

Tags: None
(comma "," separated)
dubmarauder
Registered Member
Posts
14
Karma
0
OS

Mapping Aligned Data

Wed Apr 13, 2011 5:17 am
If I have some aligned data (say from calling data() on a VectorXd), is it safe to create an aligned map starting anywhere in that data? For example:

Code: Select all
VectorXd awesome_vector = VectorXd::Random(10);
double* awesome_data = awesome_vector.data();
awesome_data += 3;
Map<Matrix2d,Aligned> awesome_map(awesome_data);


Thanks!
jitseniesen
Registered Member
Posts
204
Karma
2

Re: Mapping Aligned Data

Wed Apr 13, 2011 7:28 am
No, this is not safe. The pointer awesome_vector.data() is indeed aligned, but awesome_vector.data() + 3 may not be aligned.

In fact, if I compile and run your fragment on my computer (32-bits Linux) with SSE2 enabled (add the flag -msse2 when using GCC), then the program aborts with a message like
... Assertion ... "data is not aligned" failed


Bookmarks



Who is online

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