   map or hash_map,which is better in my situations ?
  Hello guys. I am writing a project which use a lot of maps. each map has only a few key-value pairs. I use lookup very often. insert and delete are nealy never used(at the init process , insert data into the map). Now I have 2 choices. map / hash_map. I heard that hash_map is faster than map in lookup operations. but I don't know if hash_map use more memory for it's table. if I use a lot of hash_maps and each map has a few pairs. Will it cost a lot of memory? Any helps will be appreciated ;)BTW : I use VC's STL. every animation actor has a map. and each map has 3-6 key-value pairs.   
  If you only use a few key-value pairs per map I don't think you'd benefit a lot from using a hash map, if at all. Is performance an actual problem, or do you expect it to be? Have you had any indication that std::map is too slow? If not, stick with it. On a side note, Boost's Unordered library might be a better alternative than the nonstandard hash_map if you intend to port your code to another compiler, platform or standard library implementation.   ;  3-6 key-value pairs, rare inserts? That's a no brainer: std::map.   ;Quote:Original post by WindryderIf you only use a few key-value pairs per map I don't think you'd benefit a lot from using a hash map, if at all. Is performance an actual problem, or do you expect it to be? Have you had any indication that std::map is too slow? If not, stick with it. On a side note, Boost's Unordered library might be a better alternative than the nonstandard hash_map if you intend to port your code to another compiler, platform or standard library implementation.Thank you for your help. I will stick with std::map. There isn't a performace problem. I just want to try hash_map . My program use a marco to switch between them. And thanks for the boost unordered library link.   ;  If you have really few elements, just using a vector/array with linear search may be the easiest and most efficient. (Though that obviously scales very badly if you have exceptional cases where you do need a lot of elements that are accessed frequently.)   ;Quote:Original post by Beyond_RepairIf you have really few elements, just using a vector/array with linear search may be the easiest and most efficient. (Though that obviously scales very badly if you have exceptional cases.)Thank you for suggestion . Sometimes I use strings as key. so map is better for me .   ;  I said linear search, not using key for indexing.That is:struct Something {  std::string key;  //more...}for (... ; ++it) {  if (it->key == "thekeyilookfor") {    doSomething();    break;  }}//or use equivalent STL functionality for linear search...Where you on look up search the entire array until an element is found with O(N) time complexity. The efficiency for low N comes from the sequential access and not using a hash function.But go with maps if there's any chance you will have a non-trivial number of elements.   ;  I concur with Beyond_Repair, for so few elements use a vector and use linear search. If you have a bit more elements you could use a sorted vector and binary search. It will be as fast as map and it will use less memory overhead than map.   