标签:
#include <iostream> #include <vector> using namespace std; /* * 结论: * capacity = 1, newcapacity = 2; * capacity > 1, newcapacity = (int)(capacity * 1.5); */ int main(){ int cap = -1; vector<int> ints; for(int i = 0;i<1000000;i++){ ints.push_back(i); if( cap != ints.capacity()){ cap = ints.capacity(); cout << " ints.size() = " << ints.size() << " ints.capacity() = " << cap << endl; } } cout << (int)(3*1.5) << endl; system("pause"); return 0; }
std::vector扩容机制,.按1.5倍取整扩容,如下。
标签:
原文地址:http://www.cnblogs.com/cycxtz/p/4809254.html