In C++, if I initialize a std::vector v(100);
and never try to resize()
nor reserve()
it, is the capacity()
guaranteed to stay the same all the time? I want to make sure that no memory alloc/freeing/realloc/etc is going on for perforance reasons. (Yes, it would affect performance; my functions are called all the time, and they must returrn quickly).
Resuming it all:
std::vector<float> v;
// somehow, `v' is initialized to have 100 elements
void f() { // this function must return _very_ quickly
/* do some processing, without ever calling v.resize() or v.reserve(), but
accesing v.size() and v[i] all the time */
/* it is guaranteed that no system calls (such as memory management)
will take place here? */
} // no objects on the stack whose destroyers might try to `delete' anything.
From the remarks on
vector::reserve()
in C++11 23.3.6.3 "vector capacity":