Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 527
Zack Avatar asked Oct 26 '25 10:10

Zack


1 Answers

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

like image 71
peppe Avatar answered Oct 29 '25 06:10

peppe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!