QList vs QVector revisited

后端 未结 8 2168
天涯浪人
天涯浪人 2020-12-23 22:00

My question is basically when to choose QVector and when to choose QList as your Qt container. What I already know:

  1. Qt docs: QList cl
8条回答
  •  长情又很酷
    2020-12-23 22:32

    In Qt 5.7, the documentation was changed concerning the topic discussed here. In QVector it is now stated:

    QVector should be your default first choice. QVector will usually give better performance than QList, because QVector always stores its items sequentially in memory, where QList will allocate its items on the heap unless sizeof(T) <= sizeof(void*) and T has been declared to be either a Q_MOVABLE_TYPE or a Q_PRIMITIVE_TYPE using Q_DECLARE_TYPEINFO.

    They refer to this article by Marc Mutz.

    So the official point of view has changed.

提交回复
热议问题