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?
How can I achieve this?
Moderator: Coders of Rage
-
- Chaos Rift Regular
- Posts: 173
- Joined: Thu Feb 11, 2010 9:46 pm
-
- Chaos Rift Regular
- Posts: 173
- Joined: Thu Feb 11, 2010 9:46 pm
Re: How can I achieve this?
I looked into std::map and it appears to be really inefficient for what I want to do. While searching I found this:
Definitely going to try Google's dense_hash_map for my needs. I see there's also boost::unordered_map.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
Last edited by X Abstract X on Thu Jun 17, 2010 3:27 am, edited 1 time in total.
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: How can I achieve this?
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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!