Original Post
Hi All, Have searched this, with no luck. I was under the impression that, having filled my vector with objects, i could .clear() it and the underlying capacity should not be changed? I have searched some online vector resources, and almost all of them report that .clear() simply calls .erase(begin(), end()), however, I have done a test and this is not the case. Is my version of the STL (default that is installed with vc7.1) not conforming, or is this expected behaviour? Alex The test I performed is below
std::vector<int> testVector;
int iCapacity = testVector.capacity(); //returns 0
testVector.push_back(5);
iCapacity = testVector.capacity(); //returns 1
testVector.resize(10);
iCapacity = testVector.capacity(); //returns 10
testVector.pop_back();
iCapacity = testVector.capacity(); //returns 10
testVector.erase(testVector.begin(), testVector.end());
iCapacity = testVector.capacity(); //returns 10
testVector.resize(10);
iCapacity = testVector.capacity(); //returns 10
testVector.clear();
iCapacity = testVector.capacity(); //RETURNS 0!!!!!