Vector容器介绍(一)
来源:互联网 发布:情趣睡衣淘宝买家秀 编辑:程序博客网 时间:2024/06/05 06:34
类模板
<向量>
std:: Vector
template < class T, class Alloc = allocator<T> > class vector; // generic template
Vector 是顺序容器代表数组可以改变大小。
像数组一样,Vector对于存储它们的元素使用连续的存储空间,这意味着它们的元素使用常规的指针也可以被访问,像数组一样高效。但又不像数组,它们的大小可以动态地改变,它们的存储会被容器自动处理的。
Vector在内部使用动态分配数组来存储它们的元素。当插入新元素 这个数组可能需要重新分配以便能变大,这意味着分配一个新数组并且所有元素移动。 这是一个相对昂贵的任务的处理时间,因此,vector不每次都重新分配一个元素被添加到容器中。
Vector容器可能会分配一些额外的存储空间来容纳可能的增长,因此容器可能有一个实际的容量 严格大于存储需要包含它的元素(即它的 大小 )。 Libraries 对于这样的增长,可以实现不同的策略平衡内存使用和重新分配,但在一些case下,重新分配只发生在对数增长的间隔 的大小以便插入单个元素在Vector末尾,可以提供 平摊常数时间 复杂性(见 push_back方法 )。
因此,相比数组,vector使用更多的内存,以换取能够有效地管理存储和生长动态。
相比其他动态序列容器( deques, lists and forward_lists),vector是非常有效的访问它的元素(就像数组)和相对有效的添加或删除元素 在其末尾。 对于操作包括插入或删除元素在一些特定位置除了末尾时,Vector的表现比其它的要差,有不太一致的迭代器和引用相对 lists和 forward_lists 。
容器的属性
Sequence顺序
元素在顺序容器中是一个严格的线性序列。单个元素被访问通过它们的位置。
Dynamic array动态数组
允许直接访问序列中的任何元素,甚至通过指针算法,提供了相对快速添加/删除元素在容器末尾。
Allocator-aware
这个容器使用一个allocator 对象动态地处理它的存储需求。
Template parameters
模板参数
T
类型的元素。
只有在 T 不会抛出异常当移动的时候。实现移动元素代替复制它们在重新分配的时候。
别名的成员类型 向量:value_type 。
Alloc
类型的allocator对象用于定义存储分配模型。 默认情况下, allocator 使用类模板,它定义了简单的内存分配模型,是独立类型。
别名的成员类型 Vector:allocator_type 。
member type
definition
notes
value_type
这个模板参数是 (T)
allocator_type
第二个模板参数 (Alloc)
defaults to: allocator<value_type>
reference
allocator_type::reference引用
for the default allocator: value_type&
const_reference
allocator_type::const_reference常量引用
for the default allocator: const value_type&
pointer
allocator_type::pointer指针
for the default allocator: value_type*
const_pointer
allocator_type::const_pointer常量指针
for the default allocator: const value_type*
iterator
a random access iterator to value_type
一个随机访问迭代器
convertible to const_iterator
可变常量迭代器
const_iterator
a random access iterator to const value_type
reverse_iterator
reverse_iterator<iterator>
const_reverse_iterator
reverse_iterator<const_iterator>
difference_type
a signed integral type, identical to: iterator_traits<iterator>::difference_type
usually the same as ptrdiff_t
size_type
an unsigned integral type that can represent any non-negative value of difference_type
usually the same as size_t
- Vector容器介绍(一)
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- STL vector 容器介绍
- linux文件系统之读流程 SYSCALL_DEFINE3(read, xxx)
- Java开发中的23种设计模式详解(转)
- Java正则表达式练习
- Rotate List
- 基本程序结构
- Vector容器介绍(一)
- leetcode 033 Search in Rotated Sorted Array
- fatal error C1001: INTERNAL COMPILER ERROR VC6.0BUG
- ie6、7下inline-block
- Android ListView点击事件无反应
- VS2013_Qt5打包—发布
- 传值、传指针、传引用
- 从operator=中“自我赋值”看new的抛出异常
- hdoj 1505 City Game 【dp or 单调栈】