为非常大的列表选择STL容器 [英] Choosing a STL Container for a very large list
问题描述
我有一个非常大的项目列表(〜2百万),我想优化访问速度。我使用迭代器(++ it)遍历项目。
现在代码是使用 std:map< std :: wstring,STRUCT>
。
我想知道是否值得改变std :: map与 std :: deque< std :: pair< std :: wstring,STRUCT> code>。我想我会有使用指针算术和最小化缓存未命中的优势。它的价值?
我知道剖析是答案,但我需要一个意见,在实现这个...
I have a very large list of items (~2 millions) that I want to optimize for access speed. I iterate trough the items using an iterator (++it).
Right now the code is implemented using std:map<std::wstring, STRUCT>
.
I wonder if it's worth to change std::map with a std::deque<std::pair<std::wstring, STRUCT>>
. I think I would have advantage of using pointer arithmetic and minimize cache miss. It worths ?
I know that profiling is the answer but I need an opinion before implementing this ...
推荐答案
使用deque,您将失去(或必须重新实现)键值对的优势。如果它对你的数据不是必要的,我会考虑使用deque。
With deque, you would lose ( or would have to re-implement ) the advantage of Key-Value pairs. If it's not essential for your data, I would consider using deque.
这篇关于为非常大的列表选择STL容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!