[英]map of vectors C++
嗨,如果我用C ++创建了类型为map<int, vec<double>>
的STL映射,向量是否存储在连续放置在内存中的不同键下?
从技术上讲,这将取决于map的实现,但是通常,map被实现为Tree,因此由于tree数据结构的性质,存储在内存中不是连续的。
No. * 否*
A map dynamically allocates elements as required. 映射根据需要动态分配元素。 So each
vector
could be placed anywhere in memory (and may move over time). 因此,每个
vector
都可以放置在内存中的任何位置(并可能随时间推移而移动)。
Remember also that the element storage within the vector
itself is also dynamically allocated. 还要记住,
vector
本身内的元素存储也是动态分配的。 So even if you just created a straightfoward std::vector<double> my_vectors[10]
, the elements themsleves would not be contiguous between the individual vectors. 因此,即使您只创建了一个简单的
std::vector<double> my_vectors[10]
,元素向量也不会在各个向量之间相邻。
* An implementation could conceivably allocate from an array-backed store, but you wouldn't be able to rely on this behaviour. *可以想象,实现可以从数组支持的存储中分配,但是您将不能依靠这种行为。 So it's best to assume "no".
因此,最好假设“否”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.