I'm developing game. I store my game-objects in this map:
std::map<std::string, Object*> mObjects;
std::string
is a key/name of object to find further in code. It's very easy to point some objects, like: mObjects["Player"] = ...
. But I'm afraid it's to slow due to allocation of std::string in each searching in that map. So I decided to use int
as key in that map.
The first question: is that really would be faster?
And the second, I don't want to remove my current type of objects accesing, so I found the way: store crc
string calculating as key. For example:
Object *getObject(std::string &key)
{
int checksum = GetCrc32(key);
return mObjects[checksum];
}
Object *temp = getOject("Player");
Or this is bad idea? For calculating crc
I would use boost::crc
. Or this is bad idea and calculating of checksum is much slower than searching in map with key type std::string
?