C ++:固定但运行时定义的长度数组的向量 [英] C++: Vector of fixed but runtime defined length arrays
问题描述
我知道我可以使用
std :: vector&std :: array< int,20>>myVec;
作为可在单个维度上生长的矩阵的容器.但是,必须在编译时定义 std:array<>
的大小.有什么简单的方法可以对运行时定义的数组执行相同的操作?
as a container for a matrix growable in single dimension. However std:array<>
size has to be defined in compile time. Is there any simple way how to do the same for runtime defined arrays?
我需要用它来处理数GB的数据,所以我很怀疑矢量向量会带来不必要的开销.
I need this for processing several GB of data so I'm affraid that vector of vectors would bring in unnecessary overhead.
推荐答案
我需要用它来处理数GB的数据,所以我很害怕向量的向量会带来不必要的开销.
I need this for processing several GB of data so I'm affraid that vector of vectors would bring in unnecessary overhead.
然后围绕一个一维 vector
编写一个包装器类,该类可以进行二维索引,并以一个固定维作为构造函数参数.
Then write a wrapper class around a one dimensional vector
which allows two-dimensional indexing, and give the one fixed dimension as a constructor-argument.
这是最有效的方法,因为只有一个间接级别.
That is the most efficient way, since there is only one level of indirection.
这篇关于C ++:固定但运行时定义的长度数组的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!