这是更好的一般来说,地图或向量在c ++? [英] which is better in general, map or vector in c++?
问题描述
因为我知道在向量中访问一个元素需要一定的时间,而在map中则需要对数时间。但是,存储地图比存储向量需要更少的内存。
As I know that accessing an element in vector takes constant time while in map takes logarithmic time. However, storing a map takes less memory than storing a vector.
因此,我想问哪一个更好一般?我正在考虑在我的程序中使用这两个,其中有大约1000个元素。我计划使用3维向量,这将需要1000x1000x1000元素。
Therefore, I want to ask which one is better in general? I'm considering using one of those two in my program, which has about 1000 elements. I plan to use 3 dimensional vector, which would take 1000x1000x1000 elements.
推荐答案
此问题没有正确答案。正确的问题应该是哪个更好的具体应用程序 - 插入您的项目在这里 - 。要选择正确的容器,您需要说明如何使用它。
There is no correct answer to this question. The correct question should be "which is better for the specific application --insert your project here--". To choose the correct container you need to explain how it will be used.
这篇关于这是更好的一般来说,地图或向量在c ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!