一步步学Qt,第九天-Q”STL”与STL-再看C++

一步步学Qt,第九天-Q”STL”与STL-再看C++

第一次在一步步学Qt中看到了C++的图了,或许自己也都忘记了Qt是基于C++的一个拓展的框架。不过Qt与C++的关系是莫大的,Qt她的很多的思想都引用于C++,在

一步步学Qt,第五天-Qt学习小结-Qt工作机制

也有过介绍和说明,这里不再累赘。

看书《C++ primer》( 第四版 特别版)287页,说道了在C++中容器的选用。基于不同的应用我们需要来综合选择一个更好,更高效的容器。

C++:

vectordeque 容器提供了对元素的快速随机访问,但付出的代价是,在容器的任意位置插入或删除元素,比在容器尾部插入和删除的开销更大。list 类型在任何位置都能快速插入和删除,但付出的代价是元素的随机访问开销较大。

可喜的Qt:

Qt中不仅有了像C++ list的那样的链表——QLinkedList,而且把看似和C++的list有关系的QList完全的综合了。

QList的Detailed Description

Internally, QList<T> is represented as an array of pointers to items of type T. If T is itself a pointer type or a basic type that is no larger than a pointer, or if T is one of Qt's shared classes, then QList<T> stores the items directly in the pointer array. For lists under a thousand items, this array representation allows for very fast insertions in the middle, and it allows index-based access. Furthermore, operations like prepend() andappend() are very fast, because QList preallocates memory at both ends of its internal array

QList在任意一端插入或移除都是非常快得,对于1000项以上的列表来说,在中间插入也是很快得。

可以知道,在Qt中的QList综合了vector和list。在开发中应用更加的方便。





posted @ 2011-09-01 17:13  Podevor  阅读(1020)  评论(0编辑  收藏  举报