我正在使用Qt5编写一个程序,我需要分配一个QVector <float>,使其data()指针32字节对齐。
我是否可以在不修改Qt库本身的情况下做到这一点?
我的代码如下所示:
QVector <float> vec;
vec.resize(n);
float *wricker_ptr = wricker.data(); // this should be 32-byte aligned
for (int i=0; i<n; i++)
{
wricker_ptr[i] = /* some computed value */;
}我正在使用英特尔的C++编译器。
发布于 2015-08-20 10:35:29
有两种解决办法:
std::vector和合适的分配器。QVector的数据有效载荷由alignof(T).¹分配。QVector<__m256i>或类似的和reinterpret_cast进出。不完全正确,参见http://thread.gmane.org/gmane.comp.lib.qt.devel/22326/focus=22596
https://stackoverflow.com/questions/32114519
复制相似问题