Here is a synopsis of vector:
1 2 3 4 5 6
|
template< typename Tp >
class vector {
Tp* start;
Tp* finish;
Tp* capacity;
};
|
'v' is a vector which has 5 elements of type "vector<int>". In v, start points to a block of memory at least
large enough to store 5 vectors. As you can see, vector uses 12 bytes of memory for its data members
on a 32-bit machine. Therefore, the buffer will be at least 5 * 12 = 60 bytes wide. finish and capacity
are both pointers to various locations within that buffer (unimportant for this discussion).
Each of the 5 contained vectors does the same thing. They each allocate their own block of memory
and point their own "start" pointer to it.
I cannot say what is an appropriate data structure for your purpose. It depends on your needs. If you
absolutely must have all elements in contiguous memory, then a vector of vectors is not usable.
Otherwise, because vector manages the memory for you, I'd say it is a better choice.