1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
std::vector<Vertex> vertices;
// The vector has room for no elements.
// []
vertices.push_back(Vertex(10,11));
// The vector allocates an array of size 1 and copies Vertex(10,11)
// into the array (+1).
// [Vertex(10,11)]
vertices.push_back(Vertex(20,21));
// The vector doesn't have any empty space in the array so it first
// has to allocate a new array and copy Vertex(10,11) over from
// the old array (+1).
// [Vertex(10,11), _]
// And finally it can copy Vertex(20,21) into the array (+1).
// [Vertex(10,11), Vertex(20,21)]
vertices.push_back(Vertex(30,31));
// The vector again has to create a new array, and copy the the old
// elements over (+2) ...
// [Vertex(10,11), Vertex(20,21), _, _]
// ... before it can copy Vertex(30,31) into the array (+1).
// [Vertex(10,11), Vertex(20,21), Vertex(30,31), _]
// Total number of copied: 1 + 1 + 1 + 2 + 1 = 6
|