N
Noo
Hi. I've got some code that uses vectors fairly extensively and it needs to
be efficient. Therefore I'm using reserve() quite a bit. However what other
functions (are supposed to) change the capacity?
I know that adding extra elements (e.g. by using push_back()) may do this,
if extra capacity is needed.
On the C++ implementation I'm using:
clear() seems to reset the capacity to zero.
resize() leaves the capacity as is.
operator=() does not copy the capacity. I thought for a while that, if
the elements fit into the vector on the left hand side of the = sign, the
capacity of this vector would remain the same, but copying an empty vector
seems to reset it to zero. So that after
vector<int> first;
first.reserve(1000);
be efficient. Therefore I'm using reserve() quite a bit. However what other
functions (are supposed to) change the capacity?
I know that adding extra elements (e.g. by using push_back()) may do this,
if extra capacity is needed.
On the C++ implementation I'm using:
clear() seems to reset the capacity to zero.
resize() leaves the capacity as is.
operator=() does not copy the capacity. I thought for a while that, if
the elements fit into the vector on the left hand side of the = sign, the
capacity of this vector would remain the same, but copying an empty vector
seems to reset it to zero. So that after
vector<int> first;
first.reserve(1000);