Learn C++ STL

Lesson 5 of 9 · vector: The Container You Reach for First

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

  1. Size, capacity, and the block behind them
  2. Why push_back is still cheap: the arithmetic
  3. What a reallocation breaks
  4. Giving memory back, and copying a whole vector
  5. vector<bool> is not a vector of bools
  6. The performance lab
Under the Hood: How a vector Grows, and What That Breaks | Learn C++ STL | Progsity