Page 1 of 1
How can I achieve this?
Posted: Wed Jun 16, 2010 1:56 am
by X Abstract X
I want to create a list of strings and map unique integer IDs to them. I want to be able to use string literals in my program and have the appropriate integer ID replace that string so I can eliminate the need to do a bunch of string comparisons. I also need to be able to add and remove strings from the mapping list at runtime.
Does anyone have any ideas to get this done?
Re: How can I achieve this?
Posted: Wed Jun 16, 2010 2:01 am
by Scoody
Re: How can I achieve this?
Posted: Wed Jun 16, 2010 3:06 am
by X Abstract X
I looked into std::map and it appears to be really inefficient for what I want to do. While searching I found this:
google::sparse_hash_map
map_grow 1070.01 ns
map_predict/grow 852.31 ns
map_replace 249.48 ns
map_fetch 235.62 ns
map_remove 374.92 ns
Memory used 83.0 Mb
google::dense_hash_map
map_grow 239.91 ns
map_predict/grow 30.12 ns
map_replace 24.21 ns
map_fetch 27.52 ns
map_remove 33.16 ns
Memory used 258.2 Mb
Microsoft Visual C++ 7.1 stdext::hash_map
map_grow 637.69 ns
map_predict/grow 675.36 ns
map_replace 62.54 ns
map_fetch 39.07 ns
map_remove 356.95 ns
Memory used 246.7 Mb
Microsoft Visual C++ 7.1 std::map
map_grow 3862.50 ns
map_predict/grow 3528.97 ns
map_replace 2950.20 ns
map_fetch 2682.44 ns
map_remove 4216.60 ns
Memory used 306.8 Mb
Definitely going to try Google's dense_hash_map for my needs. I see there's also boost::unordered_map.
Re: How can I achieve this?
Posted: Wed Jun 16, 2010 3:21 pm
by dandymcgee
Hell if it wasn't for the run-time requirement I'd say go with #defines. I think some sort of map is your best bet.