Module 2 · vector: The Container You Reach for First
Under the Hood: How a vector Grows, and What That Breaks
ProReading
Kenji now writes reserve before every vector, even one that holds three names. "It is faster," he says. Amara asks a short question: "By how much?" Kenji has never measured it. This lesson opens the vector, counts what it does, and then measures Kenji's habit on a real compiler.
Checking what this lesson needs for you…
What is inside Under the Hood: How a vector Grows, and What That Breaks
- Size, capacity, and the block behind them
- Why push_back is still cheap: the arithmetic
- What a reallocation breaks
- Giving memory back, and copying a whole vector
- vector<bool> is not a vector of bools
- The performance lab