在 C++ 中,如果我初始化 astd::vector v(100);
并且从不尝试resize()
也不尝试reserve()
它,是否capacity()
保证始终保持不变?我想确保出于性能原因没有内存分配/释放/重新分配/等正在发生。(是的,它会影响性能;我的函数一直被调用,它们必须快速返回)。
恢复一切:
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.