尝试下翻译STL里面的一些easy和算法。四级过了。六级刚考。顺便练练自己的英语水平。翻译的不好的地方请大神多多不吝赐教哈。方便我改正。

原来均来自:http://www.cplusplus.com/

template < class T, class Alloc = allocator<T> > class vector; // generic template

Vector

Vectors are sequence containers representing arrays that can change in size.

Just like arrays, vectors use contiguous storage locations for their elements, which means that their elements can also be accessed using offsets on regular pointers 





to its elements, and just as efficiently as in arrays. But unlike arrays, their size can change dynamically, with their storage being handled automatically by the 





container.





Internally, vectors use a dynamically allocated array to store their elements. This array may need to be reallocated in order to grow in size when new elements are 





inserted, which implies allocating a new array and moving all elements to it. This is a relatively expensive task in terms of processing time, and thus, vectors do not 





reallocate each time an element is added to the container.





Instead, vector containers may allocate some extra storage to accommodate for possible growth, and thus the container may have an actual capacity greater than the 





storage strictly needed to contain its elements (i.e., its size). Libraries can implement different strategies for growth to balance between memory usage and 





reallocations, but in any case, reallocations should only happen at logarithmically growing intervals of size so that the insertion of individual elements at the end 





of the vector can be provided with amortized constant time complexity (see push_back).





Therefore, compared to arrays, vectors consume more memory in exchange for the ability to manage storage and grow dynamically in an efficient way.





Compared to the other dynamic sequence containers (deques, lists and forward_lists), vectors are very efficient accessing its elements (just like arrays) and 





relatively efficient adding or removing elements from its end. For operations that involve inserting or removing elements at positions other than the end, they perform 





worse than the others, and have less consistent iterators and references than lists and forward_lists.

译文:

容器:Vector

原型:

template < class T, class Alloc = allocator<T> > class vector; 



描写叙述:vector是一种顺序容器,其行为类似于大小能够改变的array数组。





跟array一样。vector使用连续的存储单元来存储里面的元素。

这意味着vector能够使用正常的指针的偏移量来訪问其元素。它跟array一样的高效,可是不同于array的是,vector的大小能够动态地改变。存储他们元素的空间能够自己主动地进行伸缩。

从内部来讲。vector动态地分派空间已存储array里面的元素,当新的元素插入时,这个array须要又一次分配空间大小以容纳这个新的元素,这意味着要又一次创建一个新的array而且把原来array里面的全部元素都移动到新的array里面。

这将花费昂贵的时间代价来完毕这项任务,所以,vector并非每增加一个新的元素就又一次分配一次空间。





作为一种解决方式。vector会在一開始就分配比所需空间很多其它的空间以适应可能的增长。因此,vector会拥有大于所需空间的实际空间(比如,vector实际上仅仅须要存储2个元素,可是会分配5个元素的实际空间)。函数库能够使用不同的策略在内存使用以及又一次分配之间达到一个平衡。但不论怎样。重分配应该完毕在对数时间内,这样。在vector尾部插入单个的元素所需的时间为摊还常量时间。





因此。相比較array,vector消耗很多其它的内存作为交换以实现高效的动态增长。

相比于其它的动态顺序容器(deques,lists,forward_lists),vector能够很高效地訪问其元素(像array一样高效)以及在尾部添加和删除元素也是相当高效。可是当在尾部以外的位置插入和删除时,它的表现不如其它如list或者是forward_lists容器。而且这会令迭代器以及引用失效。

容器内容:

序列:

在顺序容器里面的元素都严格地排列在一个线性的序列里面。单个元素能够通过他们在序列中的位置直接訪问。

动态数组

同意直接訪问数组里面的任一元素,甚至是通过指针运算来訪问。提供高速在序列尾部加入/删除元素的能力

分配器

容器使用分配器对象来动态地操控其存储所需。





模板參数:

T:

数组vector里面存放的元素类型。

仅仅有T保证不会在移动时抛出异常。当重分配时实现会优化。使用移动元素来取代复制元素(C++11中的移动语义)。

Alloc:

内存分配器对象的类型,一般採用默认值。

//今天就先翻译着一点先。

STL vector的介绍(1)的更多相关文章

  1. STL vector用法介绍

    STL vector用法介绍 介绍 这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和f ...

  2. STL vector 用法介绍

    介绍 这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和for_each()中的使用.通 ...

  3. C++ stl vector介绍

    转自: STL vector用法介绍 介绍 这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if ...

  4. STL vector使用方法介绍

    介绍 这篇文章的目的是为了介绍std::vector,怎样恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和for_each()中的使用.通 ...

  5. C++STL vector详解(杂谈)

    介绍 这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和for_each()中的使用.通 ...

  6. 浅谈C++ STL vector 容器

    浅谈C++ STL vector 容器 本篇随笔简单介绍一下\(C++STL\)中\(vector\)容器的使用方法和常见的使用技巧.\(vector\)容器是\(C++STL\)的一种比较基本的容器 ...

  7. 2.3 C++STL vector容器详解

    文章目录 2.3.1 引入 2.3.2 代码实例 2.3.3 运行结果 总结 2.3.1 引入 vector 容器 动态数组 可变数组 vector容器 单口容器(尾部操作效率高) vector动态增 ...

  8. C++ STL vector容器学习

    STL(Standard Template Library)标准模板库是C++最重要的组成部分,它提供了一组表示容器.迭代器.函数对象和算法的模板.其中容器是存储类型相同的数据的结构(如vector, ...

  9. STL vector

    STL vector vector是线性容器,它的元素严格的按照线性序列排序,和动态数组很相似,和数组一样,它的元素存储在一块连续的存储空间中,这也意味着我们不仅可以使用迭代器(iterator)访问 ...

随机推荐

  1. ios之sqllite3简单使用

    SQLite3是嵌入在iOS中的关系型数据库,对于存储大规模的数据很有效.SQLite3使得不必将每个对象都加到内存中. 基本操作: (1)打开或者创建数据库 sqlite3 *database; i ...

  2. 快速部署jumpserver堡垒机

    jumpserver版本:Version 1.4.1-2 (社区版) 主机IP地址:10.0.0.105 准备环境1.安装依赖yum -y install wget sqlite-devel xz g ...

  3. SANBA服务和FTP服务

    1.samba服务 Smb主要作为网络通信协议:Smb是基于cs(client/server)架构(架构还有bs,broswer/server):完成linux与windows之间的共享:linux与 ...

  4. CSS3--- 颜色

    1.RGB是一种色彩标准,是由红(R).绿(G).蓝(B)的变化以及相互叠加来得到各式各样的颜色.RGBA是在RGB的基础上增加了控制alpha透明度的参数. 语法:color:rgba(R,G,B, ...

  5. 如何在Python中显式释放内存?

    根据Python官方文档,您可以强制垃圾收集器释放未引用的内存gc.collect().例: import gc gc.collect() 所属网站分类: python高级 > 综合&其 ...

  6. Java线程和多线程(二)——对象中的wait,notify以及notifyAll方法

    Java对象中的wait,notify以及notifyAll方法 在Java的Object类中包含了3个final的方法,这三个方法允许线程来交流资源是否被锁定.这三个方法就是wait(),notif ...

  7. Java基础学习总结(94)——Java线程再学习

    Java线程有哪些不太为人所知的技巧与用法? 萝卜白菜各有所爱.像我就喜欢Java.学无止境,这也是我喜欢它的一个原因.日常工作中你所用到的工具,通常都有些你从来没有了解过的东西,比方说某个方法或者是 ...

  8. 收集Windows 8 Metro UI 风格网站资源,觉得不错的顶啊!!

    这些资源包含:模板,框架,jQuery插件,图标集等.帮助你快速开发Windows 8 Metro UI风格的网站.本文转自虾米站长网 Frameworks & Templates For M ...

  9. left join 与left outer join的区别

    joinn 语句有三种:inner join, left outer join 和 right outer join都可以简写,分别为join,left join,right join.

  10. 【二分贪心+精度问题】F. Pie

    https://www.bnuoj.com/v3/contest_show.php?cid=9154#problem/F [题意] 给定n个已知半径的披萨,有m个人要分这n个披萨 要求每个人分到的面积 ...