In C++ Primer fourth edition, by Stanley B.Lippman, Josee Lajoie and Barbara E. Moo it states:
Because vectors grow efficiently, it is usually best to let the vector grow by adding elements to it dynamically as the element values are known.
and
Readers accustomed to using c or java might expect that because vector elements are stored contiguously, it would be best to preallocate the vector at its expected size. In fact the contrary is the case...
and
Allthough we can preallocate a given number of elements in a vector, it is usually more efficient to define an empty vector and add elements to it.
Assuming this is correct (the authors are as reputable as they come, one is a co-author of C++ itself) then can anyone give me a case that proves this statement, and explain why?
See Question&Answers more detail:os