views:

37

answers:

2

I am in the process of localizing a game. I have roughly 1% of the game assets (around 200 of 20k files) that need to be replaced per language with different assets, 1 to 1. I am mulling over the 'best' way to do this in a very RAM starved envirnoment. Here's my current list of ideas:

  • Hash off the file IDs to convert at nearly constant time 1 to another. Advantage is speed. Disadvantage is this can be memory hungry and is not as memory efficient as other methods.

  • Enter each file ID to be translated into a map. Log time lookups, but perhaps more memory efficient? I'm not as experienced with this as other solutions so I cannot say how well this will work.

  • Enter each file ID as a pair into a vector, sort the vector when done, and bsearch off it. Log time lookups and perhaps more efficicent than the map?

  • On any step, add a bit boolean table of kIsThisAssetTranslated[] on the front end to constant time bail early if the assets is unchanged.

Just looking for some experience and opinions on which methods (or something I've missed) the community would consider. I'm leaning towards the hash as this will be called per file access, but as always, the question of Ram vs performance is an interesting one.

A: 

Depends on how much RAM you have. A hashtable with 200 to 20k entries doesn't really take up much memory (by desktop PC standards). If you have to determine at runtime if a file is translated or not, then why not just create a map which contains all the files which are translated, and create subdirectories for all available languages. And then after doing the lookup, just load it from the locale directory (e.g. en-US) or add a prefix/suffix to the filename.

humbagumba
Embedded system here. I don't have directories. I have a flat list of FileIDs to work with. And it's the lookup step that is going to be the hit I am trying to avoid by hashing or sorting. And the map solution is one I have listed, but was worried about the log time lookup and the memory overhead.
Michael Dorgan
+1  A: 

You can pre-calculate the FileIDs that you need to convert. Look up perfect hashes; this may be what you need. However, 2log(200) is only 8. The overhead of hashing is significant, even more so for perfect hashing.

And remember that files are slow - 8 memory accesses for a binary search will take perhaps a microsecond, not even flash is that fast.

MSalters
Good point on the hashing overhead and the max 8 branches on 200 point. The subtle reminder that I may be worrying about a faucet drip next to a broken pipe in terms of performance is nice as well. The main thing here is that anything I do here adds to the overall performance load of the non-localized game so I'm trying to be as careful as possible.Still, you would you choose sorted vector<> or a map<> given that once these files are added, they will rarely if ever be removed?
Michael Dorgan
Obviously a case of a sorted vector. They're more efficient memory-wise (contiguous allocation).
MSalters
Sounds like what I am looking for then - thanks!
Michael Dorgan