|
|
|
|
|
by im3w1l
31 days ago
|
|
So one thing I thought of when reading this is that very often it is known ahead of time (at runtime or even compile-time) how many push_backs will be done. The programmer could make a reserve call but doesn't bother since the efficiency gain is minimal. The gain is minimal for doing this optimization at one location. But doing it everywhere, that could matter. Pushing back in a loop could maybe be optimized to a single allocation and a memcopy. |
|
For example Bjarne Stroustrup suggests you should use reservation for "avoiding invalidation of iterators" instead.