max_size, capacity and size 的区别
The max_size() function returns the maximum number of elements that the container can hold. The max_size() function should not be confused with the size or capacity functions, which return the number of elements currently in the container and the the number of elements that the container will be able to hold before more memory will have to be allocated, respectively.
vector 存在预分配机制。可以在元素不存在的情况下预分配一段空间,为以后的存储做准备。这段空间可以用reserve()调节。capacity()返回的值就是可以存放元素的个数。capacity() - size()就是下次重新进行空间分配前的预留元素个数。至于max_size()指的是一个vector结构可供储存元素的个数的上线,通常是由于寻址空间决定的。
参考链接:http://www.cnblogs.com/SelaSelah/archive/2012/05/30/2526736.html
max_size, capacity and size 的区别的更多相关文章
- java-length 、length()、size()的区别
public static void main(String[] args) { //length .length().size()的区别 //length属性 针对数组长度 String a[]={ ...
- string::capacity string::size string::length string::max_size
size_t capacity() const noexcept; #include <iostream>#include <string> using namespace s ...
- 数组序列的capacity及size函数
#include<iostream>#include<vector>using namespace std;int main(){ vector<int> i ...
- java中length,length(),size()的区别
1. java中的length属性是针对数组说的,比如说你声明了一个数组,想知道这个数组的长度则用到了length这个属性.2. java中的length()方法是针对字符串String说的,如果想看 ...
- Private Bytes,Working Set,Virtual Size的区别
http://aigo.iteye.com/blog/1930209 http://stackoverflow.com/questions/1984186/what-is-private-bytes- ...
- 关于Java中length、length()、size()的区别
length——数组的属性: length()——String的方法: size()——集合/映射的方法:(List.Set.Map) 转载自https://blog.csdn.net/qq_3323 ...
- vector 汇总
Vector成员函数 函数 表述 c.assign(beg,end) c.assign(n,elem) 将[beg; end)区间中的数据赋值给c. 将n个elem的拷贝赋值给c. c.at(idx) ...
- 数据结构图文解析之:二叉堆详解及C++模板实现
0. 数据结构图文解析系列 数据结构系列文章 数据结构图文解析之:数组.单链表.双链表介绍及C++模板实现 数据结构图文解析之:栈的简介及C++模板实现 数据结构图文解析之:队列详解与C++模板实现 ...
- C++ STL--顺序容器(vector)
STL(标准模板库) 一套功能强大的 C++ 模板类,提供了通用的模板类和函数,这些模板类和函数可以实现多种流行和常用的算法和数据结构,如向量.链表.队列.栈. C++标准模板库的核心包含以下组件: ...
随机推荐
- Ping pong
Ping pong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- C语言有关数组的几点
动态大小数组 先来看一段代码: ; int a[n]; int i; ;i<n;i++) { a[i]=i; printf("%d\n",a[i]); } 我在声明数组a时, ...
- delphi xe5 android tts(Text To Speech)
TTS是Text To Speech的缩写,即“从文本到语音”,是人机对话的一部分,让机器能够说话. 以下代码实现xe5 开发的文本转语音的方法 和访问蓝牙一样,这里用javaclass的接口实现 接 ...
- LeetCode 268
Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one ...
- LeetCode 292
Nim Game You are playing the following Nim Game with your friend: There is a heap of stones on the t ...
- LeetCode 122
Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a ...
- hdu1560 搜索
从原串的最大长度开始枚举,当某个长度的值能保存所有串时,即成功.对每个长度进行深搜,每次取某个串的第一个. #include<iostream> #include<cstdio> ...
- saltstack实战4--综合练习2
Saltstack配置管理-功能模块-安装haproxy 配置管理,我们分了3层 最底层是系统初始化部分 倒数二层是功能模块,就是具体的产品的安装了 假如你的环境需要nginx,php,memcach ...
- 通过Bresenham算法实现完成矢量线性多边形向栅格数据的转化
1.实验目的与要求 目的:通过本次实验,完成矢量线性多边形向栅格数据的转化过程: 要求:采用VC++6.0实现. 2.实验方法 采用Bresenham算法实现 3.实验材料 直线的定义:y = x/3 ...
- HDOJ2020绝对值排序
绝对值排序 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...