QList和QVector等容器的区别。

1、大多数情况下可以用QList。像prepend()和insert()这种操作,通常QList比QVector快的多。这是因为QList是基于index标签存储它的元素项在内存中,比那种依赖iterator迭代的更快捷。而且你的代码也更少。

2、如果你需要一个真正的连接着的list,且需要保证一个固定插入耗时。那就用迭代器,而不是标签。使用QLinkedList();

3、如果你需要开辟连续的内存空间存储,或者你的元素远比一个指针大,这时你需要避免个别插入操作,出现堆栈溢出,这时候用QVector

4、如果你需要一个低层的可变数量大小的数组,用QVarLengthArray就够了。他可以预先在栈中分配已知长度大小的数组,如果超过这个长度,会在堆中继续存储。默认大小256

QVarLengthArray<int, 1024> array(n + 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.
  • 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.
  • 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.
  • If you want a low-level variable-size array, QVarLengthArray may be sufficient.

QList和QVector等容器的区别相关推荐

  1. Qt工作笔记-QList (链表) QVector (数组)【转载】

    原文地址:https://blog.csdn.net/qq_33266987/article/details/53333373 C++中的list 和 vector (1). stl提供了三个最基本的 ...

  2. QList (链表) QVector (数组)

    QList (链表) & QVector (数组) C++中的list和vector stl提供了三个最基本的容器:vector/list/deque. vector和built-in数组类似 ...

  3. QList、QVector、QMap容器类

    QList.QVector.QMap容器类 QList<QString> list,创建一个列表对象,存储一列QString类型的值. list<<str<<str ...

  4. 使用QList还是QVector的问题

    文章来自gitee的大神,这里总结了一下. 关于是使用QList还是QVector的问题,一直是众多Qter的选择问题,主要是这两个玩意提供的的接口函数基本一致,比如插入.删除.取值等. - 大多数情 ...

  5. QList、QVector,QSet,std::vector,std::list直接的转换关系总结

    一:QList提供了 QList类提供了与QVector,QList,QSet,std::list四种直接的转换 QSet到QList,函数为:QList<QString>::fromSe ...

  6. Docker的实现原理以及与容器的区别

    docker和容器的区别? 其实容器的发展历史早于docker的.docker也不等同于容器,"容器"是一系列内核特性的统称. 2000年的时候,LXC容器发布,这是一种内核虚拟 ...

  7. Docker的镜像和容器的区别

    Docker的镜像和容器的区别 作者:chszs,版权所有,未经同意,不得转载.博主主页:http://blog.csdn.net/chszs 一.Docker镜像 要理解Docker镜像和Docke ...

  8. QList与QVector遍历方法与性能比较

    目录 一. 性能测试 二. QList与QVector耗时对比分析 三.QList遍历方式对比分析 四.QVector遍历方式对比分析 一. 性能测试 最近使用opengl画点云数据时发现比较卡顿,原 ...

  9. QList和QVector速度比较

    前言 测试QList和QVector的数据插入和删除的速度. 代码如下(示例): //以函数对象的形式定义查找规则--升序--MftNumber class ascendingOrder {publi ...

最新文章

  1. 启明云端方案分享| ESP32-S2 摄像头 WIFI方案应用于智能猫眼
  2. 【数据结构与算法】比较法分析查找算法与查找结构
  3. 男人离婚后一般过得怎么样?
  4. Error: failed to unmarshal json. invalid character '\'' looking for beginning of value解决方案
  5. jquery筛选方法-选取父子元素
  6. jQuery多文件上传的实例
  7. error LNK2019: unresolved external symbol __imp__JNI_CreateJavaVM@12 referenced in function _wmaim
  8. docker 下使用 Hyperf(win10)
  9. python 比较两文件夹的内容,具有通用性。
  10. IDEA取消双击shift出现的搜索框
  11. win7计算机进行重镜像,win7镜像重装系统图文教程
  12. ICPC World Finals 2015 D题 - Cutting Cheese 【二分答案】【球缺体积公式】
  13. 将Final Cut Pro X工程文件导入Premiere图文版小白级操作教程
  14. 有关人、社会的本质的思考--现代的捕蛇者说
  15. YYYY-MM-dd和 yyyy-MM-dd的区别
  16. 区块链入门教程(6)--配置使用控制台
  17. pg数据库数据量很小但是data目录很大的排查思路
  18. 手机屏幕关于VGA、QVGA、WVGA、HVGA的区别介绍
  19. readb(), readw(), readl(),writeb(), writew(), writel() 宏函数
  20. JS实现根据两点经纬度位置获取距离

热门文章

  1. c++的输入流基础知识
  2. 译文:如何使用SocketAsyncEventArgs类(How to use the SocketAsyncEventArgs class)
  3. Android 去除标题栏和状态栏的方法
  4. 在一个工程(包)下面让activity和SensorEventListener监听分离,在不同类中完成
  5. Kettle环境搭建及使用(数据迁移)
  6. 手把手gitlab最详细版安装教程centos7下安装(最新版),修复gitlab
  7. java内存不足错误_调试Java内存不足错误
  8. sf | 空间矢量对象的“聚合”操作
  9. 去掉状态条并全屏_机关单位内必须懂的道理:20条潜规则和13条定律
  10. php 生成随机数组,利用php如何获取随机数组列表