c++ - std::vector of std::vectors contiguity -
i know std::vector<t> internally stores it's data contiguously (unless std::vector<bool>) both in old c++03 standard , new c++11.
nice stackoverflow questions deal , quote standard: answer, answer.
what data inside nested vectors std::vector <std::vector <t> >? how stored?
if every internal vector needs store it's data contiguously, how can true &v[n] == &v[0] + n 0 <= n < v.size().
to phrase different, possible access all elements stored in such nested structure "simply" , sequentially (via pointer or similar) same way can done 1-d vector?
no. elements of vector stored in dynamically allocated block of memory; otherwise, capacity of vector not increase. vector object holds pointer block.
the requirement elements stored sequentially applies elements themselves, , not dynamically allocated members of elements.
Comments
Post a Comment