一:错误提示:error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned

英文提示:error C2719: 'p': formal parameter with __declspec(align('16')) won't be aligned

中文提示:error C2719: “p”: 具有 __declspec(align('16')) 的形参将不被对齐

导致整个现象的主要原因是使用了Eigen库,Eigen为了使用SSE加速,所以内存分配上使用了128位的指针。

更加准确的说法:

“First, "fixed-size" should be clear: an Eigen object
has fixed size if its number of rows and its number of columns are fixed at compile-time. So for example Matrix3f has fixed size, but MatrixXf doesn't (the opposite of fixed-size is dynamic-size).

The array of coefficients of a fixed-size Eigen object
is a plain "static array", it is not dynamically allocated. For example, the data behind a Matrix4f is just a "float array[16]".

Fixed-size objects are typically very small, which means that we want to handle them with zero runtime overhead -- both in terms of memory usage and of speed.

Now, vectorization (both SSE and AltiVec) works with 128-bit packets. Moreover, for performance reasons, these packets need to be have 128-bit alignment.

So it turns out that the only way that fixed-size Eigen objects
can be vectorized, is if their size is a multiple of 128 bits, or 16 bytes. Eigen will
then request 16-byte alignment for these objects, and henceforth rely on these objects being aligned so no runtime check for alignment is performed.”

二:解决方案:

分为四种情况:

每种情况可以对照官方的说法。可以参考如下链接

http://eigen.tuxfamily.org/dox/TopicUnalignedArrayAssert.html

在此不再重复表述。

三:我的解决方法:eigen 3.1.2有 bug,  重装Eigen;

关闭使用 预编译头;

关闭编译选项里面的16位对齐;

把Eigen::Vector4f    传值改为 传引用 Eigen::Vector4f &;

把结构体 传值 全部转换为 传引用。躲过对齐!!!

编译器选项:C/C++ ---代码生成---结构图成员对齐;

可恶:忘记了当初是怎么解决的!!!!!

四:对stl vector 进行修改:http://blog.csdn.net/pkueecser/article/details/8602656

产生问题的resize()方法,改为:

    void resize(size_type _Newsize, const _Ty & _Val)

    { // determine new length, padding with _Val elements as needed
        if (size() < _Newsize)

            _Insert_n(end(), _Newsize - size(), _Val);

        else if (_Newsize < size())

            erase(begin() + _Newsize, end());

    }

  注意其中红色部分,将传值改为传参,避免在参数栈上创建被对齐的结构的对象。然后,在我们使用std::vector< Foo<5, float> >之前包含我们的foo_vector.hpp头文件,就可以正常使用了。  注意红色部分.....

是微软坑呢?还是Eigen坑?个人感觉微软更坑!!!

后记:

       添加 修改为 869行为引用之后,引发2562行的错误,修改方式为 把第二个参数0去掉。

Eigen库对齐问题:declspec(align('16')) 的形参将不被对齐的更多相关文章

  1. 关于Eigen库在Visual Studio2013中传参对齐报错问题

    Error as follow: 具体问题及解决办法描述如下: (引自http://www.fx114.net/qa-278-97757.aspx) /************************ ...

  2. Eigen库和STL容器冲突问题

    博客参考:https://blog.csdn.net/huajun998/article/details/54311561 在程序中想使用类似于如下的容器 std::vector<Eigne:: ...

  3. NDK 开发实例二(添加 Eigen库)

    上一篇,我已经阐述了如何创建一个简单的NDK实例: NDK 开发实例一(Android.mk环境配置下) 在上一篇的基础上,我们来添加Eigen库,然后做一个简单实例. Eigen是一个高层次的C + ...

  4. Eigen库矩阵运算使用方法

    Eigen库矩阵运算使用方法 Eigen这个类库,存的东西好多的,来看一下主要的几个头文件吧: ——Core 有关矩阵和数组的类,有基本的线性代数(包含 三角形 和 自伴乘积 相关),还有相应对数组的 ...

  5. SVD分解的c++代码(Eigen 库)

    使用Eigen 库:进行svd分解,形如 A = U * S * VT. JacobiSVD<MatrixXd> svd(J, ComputeThinU | ComputeThinV); ...

  6. C++ 矩阵计算库 :Eigen库

    Eigen http://eigen.tuxfamily.org/index.php?title=Main_Page 下载http://bitbucket.org/eigen/eigen/get/3. ...

  7. Eigen库笔记整理(一)

    首先熟悉Eigen库的用途,自行百度. 引入头文件: // Eigen 部分 #include <Eigen/Core> // 稠密矩阵的代数运算(逆,特征值等) #include < ...

  8. 如何安装Eigen库和Sophus库

    * { font-family: "Tibetan Machine Uni", "sans-serif", STFangSong; outline: none ...

  9. C/C++编程笔记:C语言对齐问题【结构体、栈内存以及位域对齐】

    引言 考虑下面的结构体定义: 假设这个结构体的成员在内存中是紧凑排列的,且c1的起始地址是0,则s的地址就是1,c2的地址是3,i的地址是4. 现在,我们编写一个简单的程序: 运行后输出: 为什么会这 ...

随机推荐

  1. 洛谷P1208 [USACO1.3]混合牛奶 Mixing Milk【贪心+背包】

    由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业从一些奶农手中采购牛奶,并且每一位奶农为乳制品加工企业提供的价格是不同的.此 ...

  2. Idea 类注释和方法注释

    类注释 先打开Settings > Editor > File and Code Templates Includes Includes File Header 再随机新建个类就有类注释 ...

  3. 当样式中存在!important时无法使用show()或hide() 2017-06-11 22:25 15人阅读 评论(0) 收藏

    如果使用!important在你的样式中,比如display: none !important,此时就不能用show()了 但是我在查阅资料时发现有这样的解释, If using !important ...

  4. elasticsearch实战 修改IK源码实现词组动态更新

    下载IK源码 https://github.com/medcl/elasticsearch-analysis-ik/tree/v5.2.0 选择你对应ik的版本(ps:版本最好一致) http://l ...

  5. asp.net--CRSF

    asp.net使用了token来防止CRSF攻击 前台: 使用@Html.AntiForgeryToken(); 浏览器里面被存了一个cookie值,这个值是asp.net存给浏览器的,是readon ...

  6. C# ArcgisEngine开发中,对一个图层进行过滤,只显示符合条件的要素

    转自原文 C# ArcgisEngine开发中,对一个图层进行过滤,只显示符合条件的要素 有时候,我们要对图层上的地物进行有选择性的显示,以此来满足实际的功能要求. 按下面介绍的方法可轻松实现图层属性 ...

  7. HDU 4527

    搞了好久,发现自己是想法没错的,错在输入,必须是while(){} #include <iostream> #include <cstdio> #include <alg ...

  8. BZOJ 1455 罗马游戏 左偏树

    题目大意:给定n个点,每一个点有一个权值,提供两种操作: 1.将两个点所在集合合并 2.将一个点所在集合的最小的点删除并输出权值 非常裸的可并堆 n<=100W 启示式合并不用想了 左偏树就是快 ...

  9. codeforces Round #258(div2) C解题报告

    C. Predict Outcome of the Game time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  10. csu 1030: 素数槽

     素数槽 Description 处于相邻的两个素数p和p + n之间的n - 1个连续的合数所组成的序列我们将其称为长度为n的素数槽.比如,‹24, 25, 26, 27, 28›是处于素数23 ...