开发者

google::dense_hash_map vs std::tr1::unordered_map?

开发者 https://www.devze.com 2023-03-18 09:44 出处:网络
I\'m working on a Mobile Game for several platforms ( Android, iOS, and some maybe even some kind of console in the future ).

I'm working on a Mobile Game for several platforms ( Android, iOS, and some maybe even some kind of console in the future ).

I'm trying to decide whether to use tr1::unordered_map or google::dense_hash_map to retrieve Textures from a Resource Manager (for later binding using OpenGL). Usually this 开发者_开发问答can happen quite a few times per second (N per frame, where my Game is running at ~60 fps)

Considerations are:

  • Performance (memory and cpu wise)
  • Portability

Any ideas or suggestions are welcome.


http://attractivechaos.wordpress.com/2008/10/07/another-look-at-my-old-benchmark/

http://attractivechaos.wordpress.com/2008/08/28/comparison-of-hash-table-libraries/


go with the STL for standard containers. They have predictable behavior, and can be used seamlessly in STL algos/iterators. You're also given some performance guarantees by the STL.

This should also guarantee portability. Most compilers have the new standard implemented.


In a C++ project I developed, I was wondering something similar: which one was best, tr1:unordered_map, boost::unordered_map or std::map? I ended up declaring a typedef, controllable at compilation:

#ifdef UnorderedMapBoost
typedef boost::unordered_map<cell_key, Cell> cell_map;
#else
#ifdef UnorderedMapTR1
typedef std::tr1::unordered_map<cell_key, Cell> cell_map;
#else
typedef std::map<cell_key, Cell>  cell_map;
#endif // #ifdef UnorderedMapTR1
#endif // #ifdef UnorderedMapBoost

I could then control at compile-time which one to use, and profiled it. In my case, the portability ended up being more important, so I normally use std::map.

0

精彩评论

暂无评论...
验证码 换一张
取 消