Reputation: 1711
I have a question about std::vector
-
vector<int> vec(1,0);
while(//something_1)
{
while(//something_2)
{
...
vec.pushback(var)
...
}
process(vec.size()); //every iteration- different size
vec.clear();
vec.resize(0,0);
}
On this case - every vec.push_back(var)
there is reallocation of a new array with size bigger by one than the former array.
My question is - if there is a way using one vector, so after the inner while(//something_2)
, the vec.push_back(var)
command will push back from the first cell of vec
? instead of using vec.clear()
and vec.resize(0,0)
? so I could save the resize part and the reallocation.
The size of the vector is important for the function process(vec.size())
Thanks.
Upvotes: 1
Views: 81