[Interest] QVectors vs QLists

Konstantin Tokarev annulen at yandex.ru
Wed May 3 20:17:10 CEST 2017

03.05.2017, 21:09, "Sean Harmer" <sean.harmer at kdab.com>:
> Hi,
> On 03/05/2017 17:57, Jason H wrote:
>>  I have a app that does a lot of numeric processing,using quint32, qreal mostly (and occasional QVector3D). 10k-1M items in the data set. I generally do know the size of the dataset before I start adding to it, so I call reserve() on it. Given that, and that I've been using QMap and QVector, when I use QMap and want the keys() it gives me a QList, which I then have to call toVector() on.
>>  So this leads me to ask if I should be using QList all this time? I had thought that QList was considered harmful. [1][2][3]
>>  But "everything" seems to return to me a QList, rather than a QVector.
>>  What should I be using? (I'm Targeting 5.8 and later.)
> Depends upon your usage patterns. Do you do a lot of map operations over
> the vectors/maps? If so cache coherency may well be the biggest factor,
> in which case QVector or even std::vector may give you better
> performance than QMap. Given the current discrepancy between CPU speeds
> and memory access latencies it's hard to do better than a vector for
> pure performance as the contiguous memory layout makes better use of the
> L2 cache.

B or B+ trees tend to be more cache-friendly than red-black trees (QMap), yet
allowing faster inserts

http://panthema.net/2007/stx-btree/ (in-memory B+ tree implementation)
https://code.google.com/archive/p/cpp-btree/ (in-memory B tree implementation)

Don't believe those how will tell you that B-tress are only for storage :)

> If ease of API use is your main concern then QMap may be a better fit.
> It all depends what you are using this data for.
> Cheers,
> Sean
> --
> Dr Sean Harmer | sean.harmer at kdab.com | Managing Director UK
> KDAB (UK) Ltd, a KDAB Group company
> Tel. +44 (0)1625 809908; Sweden (HQ) +46-563-540090
> Mobile: +44 (0)7545 140604
> KDAB - Qt Experts
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest


More information about the Interest mailing list