Module 4 · array and deque: Fixed Size, and Growing at Both Ends
Under the Hood: deque's Blocks and Map, and What a Push Breaks
ProReading
Kenji rewrote his step tracker with a deque, "because a deque does everything a vector does". It reads a million step counts by index, a hundred times over, and it is slower than his old vector. Same code, same O(1) on paper. "So where did the time go?" Amara says the two are different machines, and this lesson opens both.
Checking what this lesson needs for you…
What is inside Under the Hood: deque's Blocks and Map, and What a Push Breaks
- std::array: a C array with its size in the type
- deque: a map of pointers to fixed blocks
- Where d[i] lives: the arithmetic
- When a block arrives and when it leaves
- What a push breaks: iterators, not references
- The performance lab