[Development] QList

Philippe philwave at gmail.com
Mon Mar 20 15:10:21 CET 2017


Concerning sizeof(QVector<int>) == 8

Alone, this is of course neglictable in a process space. But this allows
to use QVector inexpensively as a member variable in objects that are
instantiated many thousands of times (and in scenarios when this member
is often unused).

Yes I am aware of the QVector internals. As an old DSP and real-time
graphics programmer, I came to know a lot about performances. I even
have my own vector classes.
This means, I also know when I can get relaxed on the performance matter,
and rather select convenience and readability.

And I thanks Qt (so far), to provide me that convenience.

Philippe

> > And when size matters, have this in mind:
> > 
> > sizeof(std::vector<int>) == 32
> > sizeof(QVector<int>) == 8
> > sizeof(QList<int>) == 8
> 
> To provide a more helpful response than Marc's: I assume that you are
> aware that the Qt types just contain a pointer to a thing which contains
> the actual data (unlike std::vector), right?
> 
> That is, QVector<int> is actually (snipped from source):
>     template <typename T>
>     class QVector
>     {
>         typedef QTypedArrayData<T> Data;
>         Data *d;
>     }
> 
> Where QTypedArrayData<T> is a QArrayData, which is:
>     struct Q_CORE_EXPORT QArrayData
>     {
>         QtPrivate::RefCount ref;
>         int size;
>         uint alloc : 31;
>         uint capacityReserved : 1;
>         qptrdiff offset;
>     }
> 
> If I'm adding it up right, this gives me a total cost of 32 bytes on my
> system. Although the real cost is actually higher I'd guess, due to the
> two being allocated in separate pieces (given that malloc usually has
> some kind of book-keeping overhead).
> 
> Robin
> 
> -- 
>   Robin Burchell
>   robin at crimson.no
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development





More information about the Development mailing list