如何对共享内存(或堆)进行放置分配Eigen::Matrix?

How to do placement allocation Eigen::Matrix to Shared Memory (or Heap)?

我刚刚尝试分配一个包含 Eigen::Matrix 的实例到 Xenomai 的共享内存。

unsigned char * mem; //shared memory pointer
Robot * robot = new ((void *)(mem+ROBOT_ADDR)) Robot();

机器人 class 包含多个 Eigen::Matrix。但是,我无法在我的共享内存中分配机器人对象。

但基本分配运行良好,如下所示。

Robot * robot = new Robot(); //work well!

断言日志是:

Eigen::internal::plain_array::plain_array() [with T = double; int Size = 36; int MatrixOrArrayOptions = 0]: Assertion `(reinterpret_cast(eigen_unaligned_array_assert_workaround_gcc47(array)) & 0xf) == 0 && "this assertion is explained here: " "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" " **** READ THIS WEB PAGE !!! ****"' failed.

我已经查看了日志中的网页。但是我的情况没有解决方案。

如何对共享内存(或用户定义的特定堆)进行布局分配Eigen::Matrix?

根据链接网页:

fixed-size vectorizable Eigen objects must absolutely be created at 16-byte-aligned locations, otherwise SIMD instructions addressing them will crash.

所以问题是 mem+ROBOT_ADDR 不是 16 字节对齐的。您需要确保它是。