[Interest] QVector / std::vector and memory alignment
Philippe
philwave at gmail.com
Wed Dec 28 17:34:37 CET 2016
Given an aligned type such as:
struct alignas(2048) foo
{
char t[55];
};
I was pleasantly surprised that QVector<foo> provides aligned data (see my example further, using Qt 5.8 RC)
I could not see this officially mentionned in the Qt documentation.
Yet, this is obviously very useful. Hence, is it a documentation omission, or "an implementation detail we can't rely on" ?
std::vector does not have this property. As demonstrated with the following code (this is one example but I tried many)
Tested on VC2015 Update-3 and Clang (XCode 8.1)
qDebug() << sizeof(foo); // gives 2048
QVector<foo> v;
v.resize(10);
qDebug() << intptr_t(v.data()) % sizeof(foo); // gives 0
std::vector<foo> sv;
sv.resize(10);
qDebug() << intptr_t(sv.data()) % sizeof(foo); // gives not 0 (usually)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20161228/c1534db4/attachment.html>
More information about the Interest
mailing list