[Interest] QVectors vs QLists

André Somers andre at familiesomers.nl
Thu May 4 10:42:49 CEST 2017


Hi,


Op 03/05/2017 om 20:15 schreef Jason H:
>
>> Sent: Wednesday, May 03, 2017 at 1:53 PM
>> From: "Konstantin Shegunov" <kshegunov at gmail.com>
>> To: "Jason H" <jhihn at gmx.com>
>> Cc: "Qt Project" <interest at qt-project.org>
>> Subject: Re: [Interest] QVectors vs QLists
>>
>> I'll throw my 2 cents in, in addition to Sergio's comment on
>> iterator-based traversing.
>>
>> 1) If you don't absolutely need key ordering, I'd suggest a hash table
>> (e.g. QHash) due to the amortized time lookup/insertion. If you use a
>> numerical key for the QMap, I'd definitely consider switching to a
>> hash to offset the cost of the tree rotations, which is also
>> especially useful (I believe) if the value type is copy-heavy.
>>
>> 2) Prefer QVector over QList but not fanatically. If your data's
>> movable (declared as such) and the size of `void *` (e.g. keeping
>> implicitly shared classes' instances) then QList should fare just
>> fine.
>
> Thanks both of you, I am putting effort in to use the classes wisely. Aside fro this keys() thing, I think I'm on point, I only use QMap where I need fast min/max/ordered key lookup, else I'm using QVector. My calls to keys() are few, but they happen on large datasets. 
>
> It sounds like I should just use QLists for keys() until Qt6.
>
Also consider if you need the COW features of the Qt containers, or if
you could do without. If you don't need them, you can probably gain a
speedup if you use the std containers instead. So, perhaps rely on
std::vector instead of QVector, std::unordered_map instead of QHash and
std::map instead of QMap.

André




More information about the Interest mailing list