J
JDT
Hi,
My understanding about vector's reserve() is to allocate memory for the
vector. If so, is it right that each push_back() in the following loop
causes no memory reallocation and its execution time should be constant
(i.e. internally, only one value is copied and then the integer "size"
is increased by one)? Thanks for any help.
vector<int> v;
v.reserve(100);
for (int i=0; i<100; i++)
v.push_back(i);
JD
My understanding about vector's reserve() is to allocate memory for the
vector. If so, is it right that each push_back() in the following loop
causes no memory reallocation and its execution time should be constant
(i.e. internally, only one value is copied and then the integer "size"
is increased by one)? Thanks for any help.
vector<int> v;
v.reserve(100);
for (int i=0; i<100; i++)
v.push_back(i);
JD