Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eigen alignment issues

Do the memory alignment issues with Eigen listed in the documentation still apply with C++11? It seems that C++11 can already take care of properly aligning objects on the stack and on the heap, with alignas and std::allocator which supports alignment.

like image 887
tmlen Avatar asked Apr 09 '15 10:04

tmlen


2 Answers

Yes, the alignment issues are still present in C++11. The alignas specifier has no effect on dynamic allocations, which can thus still cause misalignments resulting in assertions thrown by Eigen.

You will have to continue to use the facilities Eigen provides for aligned allocation, such as EIGEN_MAKE_ALIGNED_OPERATOR_NEW for allocating objects or Eigen::aligned_allocator<T> for aligning containers.

like image 135
Peter K Avatar answered Nov 06 '22 10:11

Peter K


While the question is about C++11 specifically, it is worth noting that a combination of the upcoming Eigen version 3.4 with a C++17 compliant compiler will free us from the need to use EIGEN_MAKE_ALIGNED_OPERATOR_NEW and Eigen::aligned_allocator<T>. The former macro is actually even empty then. This is possible by a new form of operator new that is specifically designed to support overalignment.

like image 1
lubgr Avatar answered Nov 06 '22 09:11

lubgr