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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.