A walkthrough of four mechanisms working behind every push_back() call — exponential growth and amortized O(1), the growth factor's effect on memory reuse, cache performance from contiguity, and the silent noexcept trap in move semantics during reallocation.
std::vector — Four Mechanisms Behind Every push_back()
by Gracjan Olbinski
From the article:
"You call push_back() a thousand times. The vector reallocates about ten. Behind that simple interface, four mechanisms are working together — each one invisible during normal use, each one shaping your performance in ways that push_back() will never tell you about."

Add a Comment
Comments are closed.