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)

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to