2 ms·
I very much agree that many people use rules like these as excuses to write shitty code. From the post you linked though: > Not reserving space in a vector wh
by account42 6y ago
I very much agree that many people use rules like these as excuses to write shitty code.
From the post you linked though:
> Not reserving space in a vector when the size is known
std::vector::reserve() is actually not something you should always use when you are adding a number of elements as it will (typically) grow the vector to exactly what you ask. If your function then gets called in a loop to append to the same vector multiple times you end up with quadradtic run time that is normally avoided by the geometric growth done when you just append without reserving.