[Development] QList

Robin Burchell robin.burchell at crimson.no
Mon Mar 20 13:13:23 CET 2017


Hi Philippe,

On Mon, Mar 20, 2017, at 09:28 AM, Philippe wrote:
> >>Even our API guidelines stipulate that you should make common things easy and 
> >>not-so-common things possible. Sharing is _not_ common and it need not be as 
> >> easy as common tasks. I
> 
> Maybe for you, but in my works, sharing _is_ common, convenient and safe.
> And overal usage of COW is one of the concept that makes Qt stand apart.
> From my POV, COW largely pay off its minimal performance cost.
> When performance is a high priority, _an uncommon case_, then using
> alternate containers is always possible and we don't need Qt for this.

I don't know your background, but let's assume you are primarily a user
of Qt (thus: an application developer of some kind), you may consider
performance to be unimportant, or important only in isolated areas of
your application.

Consider, however, the point of view from many of the people on this
list: as Qt uses itself in its own implementation, Qt must have
acceptable performance for end user applications to be able to have
acceptable performance at all - whether or not it is a priority to those
developers.

A few concrete examples of where data types matter a lot: signal
connections (involves storing a bunch of data), QObject (particularly
QObject::children, as already mentioned), event handling from the
operating system (or the application itself: the event posting mechanism
in QCoreApplication)...

> 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



More information about the Development mailing list