I know that std::vector
uses a contiguous block of memory, but I often see people use vectors of vectors, even when they modify the number of elements in these vectors contained within an outer vector. Won't this lead to efficiency problems when an inner vector need to be resized as all the following vectors will have to have their elements moved as well?
In other words, in the following code, won't growing lists[0]
trigger the moving of the elements of the 99 sub vectors following it too, and not just lists[0]
?
std::vector<std::vector<int>> lists;
lists.resize(100);
// use and grow sub vectors
// ...
lists[0].push_back(88); // ← !