问题描述
我知道 很好的stackoverflow问题,处理这个问题并引用标准:。 嵌套向量中的数据 如果每个内部向量都需要连续存储数据,那么 要对此略有不同,可以访问所有元素在这样的嵌套结构中简单地并且顺序地(通过指针或类似物)以与对于1-D向量可以完成的相同的方式进行? 否。 元素按顺序存储的要求仅适用于元素本身,而不适用于这些元素的任何动态分配成员。 I know that Nice stackoverflow questions that deal with this and quote the standard: answer, answer. What about the data inside nested vectors If every internal vector needs to store it's data contiguously, how can it be true that To phrase this slightly different, is it possible to access all the elements stored in such nested structure "simply" and sequentially (via a pointer or similar) the same way it can be done for a 1-D vector? No. The elements of a The requirement that the elements be stored sequentially applies only to the elements themselves, and not to any dynamically allocated members of those elements. 这篇关于std :: vector of std :: vectors contiguity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! std :: vector< T>
在内部连续地存储它的数据(除非 std :: vector< bool> code>标准和
C ++ 11
标准中的 / p>
std :: vector< std :: vector< T> >
?如何存储?
& v [n] = =& v [0] + n,对于所有0 。
向量
的元素存储在动态分配的存储器块中;否则,向量
的容量不能增加。 向量
对象只保存指向该块的指针。
std::vector<T>
internally stores it's data contiguously (unless it is std::vector<bool>
) both in the old C++03
standard and the new C++11
.std::vector <std::vector <T> >
? How is that stored?&v[n] == &v[0] + n for all 0 <= n < v.size()
.vector
are stored in a dynamically allocated block of memory; otherwise, the capacity of the vector
could not increase. The vector
object just holds a pointer to that block.