Registered Member
|
The example given at last in the page below is confusing.
http://eigen.tuxfamily.org/dox-devel/TopicStructHavingEigenMembers.html Should it have been "enum { NeedsToAlign = (sizeof(Vector)%16)==0 };" ? I have to say manually forcing alignment is really annoying! The users need to add EIGEN_MAKE_ALIGNED_OPERATOR_NEW to every and each class in the inheritance/composition trees --- even if they are not direct users of Eigen library. P.S. Are the new features "C++11 alignment specifiers" relevant to this problem? |
Moderator
|
you can declare your attributes with Eigen::DontAlign, e.g.:
Matrix<float,4,4,DontAlign> m_mat; If a function use m_mat several times, then you can copy it at the beginning of the function into an aligned Matrix4f to take advantage of SSE. |
Moderator
|
another solution is to store your fixed size object into a private struct which is dynamically allocated, e.g.:
struct Foo_d { EIGEN_MAKE_ALIGNED_OPERATOR_NEW Matrix4f m_mat; Vector2d m_vec; etc. }; class Foo { Foo() { init_d(); } ~Foo() { delete d; } private: void init_d() { d = new Foo_d; } Foo_d* d; }; |
Moderator
|
for the record these two options have been added to the documentation
|
Registered Member
|
Thank you for your reply. I know some of those workaround. But what I'd like to know is that is there a schedule or plan of fixing this problem completely -- I mean a solution that completely encapsulates codes for alignment inside Eigen and thus won't entail any further work on the users.
The present situation is that whenever a downstream library uses Eigen, it has to tell its users how to take care of this alignment issue. That's really not a satisfying solution in my view. |
Moderator
|
well this is a limitation of C++ which apparently is not solved by the new standard.
Note that with the two above solutions, the user of library using Eigen will be affected only if he/she directly manipulated Eigen's objects. |
Registered Member
|
Sorry for digging this old post out. Usually, I prefer a boost::shared_ptr<Foo_d> to a raw Foo_d*. Boost provides a method to make shared object --- shared_ptr<T> make_shared( Args && ... args ) and shared_ptr<T> allocate_shared( A const & a, Args && ... args ) (http://www.boost.org/doc/libs/1_48_0/libs/smart_ptr/make_shared.html#functions)
I have confirmed that make_shared(...) won't meet the alignment requirement of Foo_d. allocate_shared(...) will use an user-supplied allocator, so I wonder can it make shared Foo_d objects? If so, would you please show me the code (I guess one or two lines only) doing that? I'm really a layman of allocator stuff . Thanks. |
Moderator
|
you need to pass this allocator:
Eigen::aligned_allocator<Foo_d> to allocate_shared(...); |
Registered Member
|
Thanks. Normally speaking, should/may I save and use a named allocator multiple times? For example:
Assume the constructor of Foo_d takes a std::string argument
or should I change these to
|
Moderator
|
That depends on the allocator and on the application. In this case since Eigen::aligned_allocator is empty this does not really matter.
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]