reserve 실험을 string에 이어 vertor에서도 했다.
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
vector<string> s;
cout << "1 - s.capacity() : " << s.capacity() << endl;
s.reserve(10);
cout << "2 - s.capacity() : " << s.capacity() << endl;
s.reserve(100);
cout << "3 - s.capacity() : " << s.capacity() << endl;
s.reserve(1000);
cout << "4 - s.capacity() : " << s.capacity() << endl;
s.reserve(100);
cout << "5 - s.capacity() : " << s.capacity() << endl;
s.reserve(10);
cout << "6 - s.capacity() : " << s.capacity() << endl;
s.reserve(1);
cout << "7 - s.capacity() : " << s.capacity() << endl;
s.reserve(0);
cout << "8 - s.capacity() : " << s.capacity() << endl;
return 0;
}
결과)
g++ 2.9.6
$ ./a.out
1 - s.capacity() : 0
2 - s.capacity() : 10
3 - s.capacity() : 100
4 - s.capacity() : 1000
5 - s.capacity() : 1000
6 - s.capacity() : 1000
7 - s.capacity() : 1000
8 - s.capacity() : 1000
g++ 3.2.2
$ ./a.out
1 - s.capacity() : 0
2 - s.capacity() : 10
3 - s.capacity() : 100
4 - s.capacity() : 1000
5 - s.capacity() : 1000
6 - s.capacity() : 1000
7 - s.capacity() : 1000
8 - s.capacity() : 1000
이 경우는 2.9.6, 3.2.2 모두 reserve()를 지원했다. shrink는 안됐다.
댓글 없음:
댓글 쓰기