[转]QList和QVector等容器的区别

中文

  1. 大多数情况下可以用QList。像prepend()insert()这种操作,通常QListQVector快的多。这是因为QList是基于index标签存储它的元素项在内存中,比那种依赖iterator迭代的更快捷。而且你的代码也更少;
  2. 如果你需要一个真正的连接着的list,且需要保证一个固定插入耗时。那就用迭代器,而不是标签。使用QLinkedList();
  3. 如果你需要开辟连续的内存空间存储,或者你的元素远比一个指针大,这时你需要避免个别插入操作,出现堆栈溢出,这时候用QVector;
  4. 如果你需要一个低层的可变数量大小的数组,用QVarLengthArray就够了。他可以预先在栈中分配已知长度大小的数组,如果超过这个长度,会在堆中继续存储。默认大小256

English

  1. For most purposes, QList is the right class to use. Operations like prepend() and insert() are usually faster than with QVector because of the way QList stores its items in memory (see Algorithmic Complexity for details), and its index-based API is more convenient than QLinkedList's iterator-based API. It also expands to less code in your executable;
  2. If you need a real linked list, with guarantees of constant time insertions in the middle of the list and iterators to items rather than indexes, use QLinkedList;
  3. If you want the items to occupy adjacent memory positions, or if your items are larger than a pointer and you want to avoid the overhead of allocating them on the heap individually at insertion time, then use QVector;
  4. If you want a low-level variable-size array, QVarLengthArray may be sufficient.

来源: http://qimo601.iteye.com/blog/1463047

本文作者:vanxkr

本文链接:http://www.vanxkr.com/2018/8/QList-QVector

版权声明:本博客所有文章除特别声明外,均采用CC BY-NC-SA 3.0许可协议。转载请注明出处!

python爬虫url管理器[url_version_manage.py]
0 条评论
已登录,注销 取消