[Development] HEADS UP: Don't use QList, use Q_DECLARE_TYPEINFO
Marc Mutz
marc.mutz at kdab.com
Sat Jul 11 04:20:52 CEST 2015
On Friday 10 July 2015 21:33:30 Thiago Macieira wrote:
> You really want to use a vector for everything except if:
> - you NEED O(1) insertion or deletion anywhere → use QLinkedList
> - you want stable element pointers even if the container is modified
> - copying your type is expensive and your container gets modified a lot
>
> The first two are extremely rare.
Indeed. So rare that in my professional career, with lots of STL use (I even
wrote a custom allocator once - yes, in production code), I have only ever
used std::list only to implement a poor man's concurrent queue (and that
requires splice(), which QLinkedList doesn't have):
// pop_front:
std::list<C> next;
{
const QMutexLocker locker(queueMutex);
next.splice(next.begin(), queue, queue.begin());
}
// use next.front()
// push_back
std::list<C> newItem = { ... };
{
const QMutexLocker locker(queueMutex);
queue.splice(queue.end(), newItem);
}
And the third is so hard to predict that one shouldn't try, but see whether
QVector doesn't offer enough performance.
So im my book, using QLinkedList or QList-for-list-behaviour or std::list is
almost certainly a premature optimisation, and in need of defending in the
commit message.
Thanks,
Marc
--
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - The Qt Experts
More information about the Development
mailing list