[英]std::vector(n, std::vector(n)) or std::vector(n*n)?
What way to store nm matrix is more efficient? 哪种方式存储nm矩阵更有效? To create a vector of n vectors of size m or to a create big vector of size nm?
要创建大小为m的n个向量的向量还是创建大小为nm的大向量?
How is a vector of vectors stored in the memory? 向量的向量如何存储在存储器中? Does it contains only references/pointers or whole vectors?
它仅包含引用/指针还是整个向量?
It's more efficient to use a single vector of size N x M. This way all the memory is contiguous, and there is only a single pointer to all of it, rather than N pointers. 使用大小为N x M的单个向量更有效。通过这种方式,所有内存都是连续的,并且只有一个指向所有内存的指针,而不是N个指针。
A vector of vectors is stored as a pointer to an array of pointers, each of which points to an array of values. 向量的向量作为指向指针数组的指针存储,每个指针指向一个值数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.