vector::shrink_to_fit
過剰な機能、超える能力、余剰容量を破棄します。
void shrink_to_fit(
);
使用例
// vector_shrink_to_fit.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
vector <int> v1;
//vector <int>::iterator Iter;
v1.push_back( 1 );
cout << "Current capacity of v1 = "
<< v1.capacity( ) << endl;
v1.reserve( 20 );
cout << "Current capacity of v1 = "
<< v1.capacity( ) << endl;
v1.shrink_to_fit();
cout << "Current capacity of v1 = "
<< v1.capacity( ) << endl;
}
必要条件
ヘッダー: <vector>
名前空間: std