使用Eigen库和stl容器时遇到问题
来源:互联网 发布:sql语句时间格式化 编辑:程序博客网 时间:2024/06/07 02:21
在程序中使用了这样的容器
std::vector<Eigen::Matrix4f> p;由于Eigen自身分配空间方法与stl空间分配的问题,在执行push_back()操作时,有时会弹出如下的错误信息,并导致程序崩溃。
Assertion failed: (reinterpret_cast<size_t>(array) & 0xf) == 0 && "this assertion is explained here: " "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" " **** READ THIS WEB PAGE !!! ****"
根据提示访问了http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html网页,网页中显示可能的原因如下:
Cause 1: Structures having Eigen objects as members
If you have code like this,
then you need to read this separate page: Structures Having Eigen Members.
Note that here, Eigen::Vector2d is only used as an example, more generally the issue arises for all fixed-size vectorizable Eigen types.
Cause 2: STL Containers or manual memory allocation
If you use STL Containers such as std::vector, std::map, ..., with Eigen objects, or with classes containing Eigen objects, like this,
then you need to read this separate page: Using STL Containers with Eigen.
Note that here, Eigen::Matrix2f is only used as an example, more generally the issue arises for all fixed-size vectorizable Eigen types and structures having such Eigen objects as member.
The same issue will be exhibited by any classes/functions by-passing operator new to allocate memory, that is, by performing custom memory allocation followed by calls to the placement new operator. This is for instance typically the case of std::make_shared
or std::allocate_shared
for which is the solution is to use an aligned allocator as detailed in the solution for STL containers.
Cause 3: Passing Eigen objects by value
If some function in your code is getting an Eigen object passed by value, like this,
then you need to read this separate page: Passing Eigen objects by value to functions.
Note that here, Eigen::Vector4d is only used as an example, more generally the issue arises for all fixed-size vectorizable Eigen types.
Cause 4: Compiler making a wrong assumption on stack alignment (for instance GCC on Windows)
This is a must-read for people using GCC on Windows (like MinGW or TDM-GCC). If you have this assertion failure in an innocent function declaring a local variable like this:
then you need to read this separate page: Compiler making a wrong assumption on stack alignment.
Note that here, Eigen::Quaternionf is only used as an example, more generally the issue arises for all fixed-size vectorizable Eigen types.
The case of std::vector
The situation with std::vector was even worse (explanation below) so we had to specialize it for the Eigen::aligned_allocator type. In practice you must use the Eigen::aligned_allocator (not another aligned allocator), and #include <Eigen/StdVector>.
Here is an example:
- 使用Eigen库和stl容器时遇到问题
- 运行PLSLAM时,遇到Eigen对齐问题
- Eigen使用vector容器出错
- 编译安装eigen时遇到的问题 GLUT_Xmu_LIBRARY (ADVANCED)
- Eigen的使用时遇到error C2338: INVALID_MATRIX_PRODUCT问题解决
- 使用STL map 时遇到的两个问题
- eigen库使用心得
- Eigen库的使用
- Eigen库使用
- Eigen库使用注意事项
- STL容器Set和Multisets使用
- STL容器Maps和Multimaps使用
- 一个Eigen库使用时的出现的问题(complex的头文件兼容性)
- struts2的容器和spring的容器在产生actionbean时遇到的问题
- C++Eigen库的配置和基本使用
- Qt使用Eigen矩阵库
- Eigen库使用报错
- makefile链接使用eigen库
- javaweb百度鹰眼上传轨迹接口
- 第一周、课时9:数据类型区分和数据类型检测
- 二进制转换
- java处理高并发高负载类网站的优化方法
- .net 去除字符串中标点符号
- 使用Eigen库和stl容器时遇到问题
- java调用webservice方法
- centos7安装mysql
- 三分钟学会用SpringMVC搭建最小系统(超详细)
- shiro 动态修改资源权限不需要重启项目或者重新登录用户
- Stata 外部命令:最常用和最新的命令
- eclipse:新建WindowBuilder工程后如何排版的问题
- JavaNIO学习(与IO比较)
- css之position