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.

- 8,533
- 5
- 31
- 84
-
Are you talking about the part of the documentation that references a gcc bug? – Craig S. Anderson May 20 '15 at 06:10
-
2Also that you can't pass Eigen object by value, need use a custom allocator for container, a spezialized `std::vector`, and the macro to overload `operator new` in classes that contain Eigen objects. Because in C++11 memory alignment seems to be supported for for stack and heap memory. – tmlen May 20 '15 at 06:27
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.

- 1,372
- 8
- 24
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.

- 37,368
- 3
- 66
- 117