Skip to main content
gamedev.net
🔒 Locked

std::map perfomance

Started by Biorobic Apr 18, 2004 at 5:57 PM 5 replies 950+ views
Original Post
Biorobic
Biorobic
hello everyone, i''m currently developing my own little scripting language for my game. i got it nearly finished, now i got one question (well, yes, i should have thought about this earlier): i''m using std::map to store variables etc. and access them quickly, untill now, i thought std::map is an implentation of a hash table... i know that stl containers are fast and optimized so i used that- now i read that std::map is kind of BST with bidirectional order. i got my own hash table structure, but its not the best one so i want to ask before changing from std::map to my structure: is std::map fast enough to handle such situations (or can it somehow be compared to a hash table when talking of speed), i did some testings on my own, but i cant see big differences. thanks for any comment in advance, bio
kuphryn
kuphryn
std::map is a good solution.

Kuphryn
intransigent-seal
intransigent-seal
I expect std::map<> is fast enough for your needs. There is also the (non-standard, iirc, but I believe it's in STLport) std::hash_map<>, which should be quite easy to plug in, if you find later that std::map<> isn't fast enough for your needs.

I would strongly suggest that you continue to use std::map<> until you actually have emperical evidence that it is too slow for your purposes (meaning, you're using your scripting language for something, it isn't fast enough, and you've done a bit of profiling to make sure that it's the std::map<> in your scripting language that's the bottleneck). If you do eventually find that std::map<> isn't fast enough, then try replacing it with std::hash_map<> or your own hash table code.

Edit: lol. In the time it takes me to write a reply like this, two people can give one-line answers containing the bulk of what I'm trying to say.

John B

[edited by - JohnBSmall on April 18, 2004 7:08:25 PM]
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Premandrake
Premandrake
std::map is generally implemented as a red-black tree, so it is O(log n) for access, insertion and deletion. It is very useful if you need your elements in a sorted order, but if you don't a better fit would be std::hash_map, which is a hash table implementation of map (ie. amortized O(1) access, insertion and deletion times).

If you haven't seen big-O notation around a lot, O(log n) means that the operation cost is proportional to the log of the amount of data you have stored in the structure. O(1) means it executes in constant time, so the number of elements is mostly irrelevant.

However, std::hash_map is sometimes not included in older versions of the STL, if it isn't take a look at STLPort (hit google).

[Edit: okay, too slow on the draw ]

[edited by - premandrake on April 18, 2004 7:08:36 PM]
Biorobic
Biorobic
thanks to everyone for quick and quality answers, thats all i wanted to know, thanks..

bio

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.