3 ms·
From C++: calling vector<T>::reserve in a loop can lead to quadratic behavior. For example: std::vector<int> v; while (...) { v.reserve(v.size()
by detrino 12y ago
From C++: calling vector<T>::reserve in a loop can lead to quadratic behavior. For example:
std::vector<int> v;
while (...) {
v.reserve(v.size() + 3);
v.push_back(0);
v.push_back(1);
v.push_back(2);
}
Rust has both reserve and reserve_exact to overcome this gotcha.