Sequential data structures

One of the most common data structures that developers use is the dynamically growing one-dimensional array, usually referred to as a vector. The STL provides a container with the same name: std::vector. The key idea behind the vector is that it contains items of the same type placed sequentially in memory. For example, a vector consisting of 4 byte integers would have the following memory layout. Each box represents a four byte space. The indexes of the vector are on the right-hand side of the following diagram:

The physical structure of the vector allows any of its elements to be accessed in real time.

We should ...

Get Expert C++ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.