vector::capacity
2016-07-23 12:55
295 查看
vector::capacity(容量)
Return size of allocated storage capacityReturns the size of the storage space currently allocated for the vector, expressed in terms of elements.
This capacity is not necessarily equal to the vector size. It can be equal or greater, with the extra space allowing to accommodate
for growth without the need to reallocate on each insertion.
Notice that this capacity does not suppose a limit on the size of the vector. When this capacity is exhausted and more is needed,
it is automatically expanded by the container (reallocating it storage space). The theoretical limit on the size of a vector is
given by member max_size.
The capacity of a vector can be explicitly altered by calling member vector::reserve.
Parameters
none
Return Value
The size of the currently allocated storage capacity in the vector, measured in terms of the number elements it can hold.Member type size_type is an unsigned integral type.
capacity的意思是容量,此方法返回的是该vector对象最多能容纳多少个元素。 size的意思是大小,此方法是返回该vector对象当前有多少个元素。
// comparing size, capacity and max_size #include <iostream> #include <vector> using namespace std; int main () { std::vector<int> myvector; // set some content in the vector: for (int i=0; i<100; i++) myvector.push_back(i); cout << "size: " << (int) myvector.size() << '\n'; cout << "capacity: " << (int) myvector.capacity() << '\n'; cout << "max_size: " << (int) myvector.max_size() << '\n'; return 0; }
相关文章推荐
- Python之定向爬虫Scrapy
- CentOS系统操作mysql的常用命令
- adb无线调试
- IO流读取键盘录入
- UVA12558->IDDFS
- LLDB之理解LLDB基本命令语法
- 5. Longest Palindromic Substring && 214. Shortest Palindrome && 336. Palindrome Pairs
- 【VS开发】windows注册ActiveX控件
- eclipse编写java时printf出现错误
- soft raid5阅读笔记之十--状态标志
- 剑指offer 34题 【时间空间效率的平衡】丑数
- 【VS开发】动态创建ActiveX控件
- Yii CModel中rules验证规则
- Android之AsyncTask异步加载(三)
- Spring之AOP面向切面编程实现(一)
- POJ 1915 BFS题目
- 软件升级包封装方法以及软件升级方法
- Android全部源码导入Eclipse
- 微信错误:errcode=45015, errmsg=response out of time limit or subscription is canceled
- MySQL隔离级别