简体   繁体   中英

Memory aligned QVector().data()

I'm writing a program using Qt5, and I need to allocate a QVector <float> having its data() pointer 32-byte aligned.

Is there anyway I could do this without modifying the Qt library itself?

My code looks something like this:

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 */;
}

I'm using Intel's C++ Compiler.

Two solutions come to mind:

  1. Forget it: use std::vector and a suitable allocator. QVector 's data payload is allocated with alignof(T)
  2. The 32 byte alignment smells of SIMD processing, so you could use a QVector<__m256i> or similar and reinterpret_cast in and out.

¹ not entirely true, see http://thread.gmane.org/gmane.comp.lib.qt.devel/22326/focus=22596

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM