Can vector of vectors get reallocated because one of elements got reallocated?

c++, stdvector

Solution

No, it won't have any incidence: the implementation of vectors is based on an array in most case (it's pretty much the idea of vectors), though this is not set in stone in the language specification. At any rate, the dynamic nature of vectors precludes any form of sequence inlined in the data structure, ie. the sequence of elements managed by the `vector` class cannot be inside the `vector` class, but is necessarily a chunck of memory located elsewhere, with a pointer in the class.

Your datatype is therefore similar to a dynamic array of pointers to dynamic arrays. Reallocating one pointed array will not have an effect on the pointer array.

Problem

Lets say I have a vector of vectors: ``` vector< vector<int> > table; ``` I know that vector can get reallocated if it doesn't have sufficient capacity. I am wondering if there is a possibility of vector table reallocating if I do this: ``` table[i].resize(1000); ``` Is it possible that reallocation of table[i] also reallocates table?

Original source