• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] The advantages of game cache

Status
Not open for further replies.
Level 2
Joined
Aug 24, 2004
Messages
11
What makes using game cache a better option than using arrays? I can understand using game cache if you are storing hundreds or thousands of values that you will rarely access, but storing a few dozen values in the cache seems like a popular thing to do. Wouldn't using arrays be so much better with just a few values? Also, wouldn't the increased latency introduced by using the hard drive instead of RAM increase lag?
 
Level 1
Joined
Aug 28, 2004
Messages
2
Well, especially when letting other people copy and paste your code, you don't have to worry about duplicating variable names that user might already have. I suppose that it is much cleaner looking to write GetCacheWhatev() than affix that udg_ crap to everything, as well. And if you are actually using the cache quite a bit, it really does simplify lists.

On my reasonably fast machine, the game cache has never caused any amount of latency or lag. I use the cache in a set of parsing functions, which tokenate, colour and store strings (among other operations) pretty much all in the same go. You can expect those functions to call InitGamecache several dozen times per string (of around say forty characters). Using the gamecache might be slower than using variables, I've never tested (and frankly don't know how), but it at least appears to run as fast as variables, ie instantly.

Saving the gamecache and reloading all caches from disk might be two functions that would slow the game down, but I don't see the need to do either any more than once a game.

All of that being said, the real reason the cache is used so frequently is that it is in the heighth of fashion. Whether the situation warrants it or not, you are simply obliged to use it.
 
Level 2
Joined
Apr 13, 2004
Messages
29
It is a common misunderstanding that gamecache works on the disk. It is implemented as a hash table in memory and only when you call the natives to store the gamecache to disk it is actually written there (which you do not want when using it in that way).
People usually use it mainly because you can use it as an associative array. So you are not limited to store info under integers from 0..JASS_MAX_ARRAY_SIZE as with arrays.
A warning: The gamecache is a hashtable and it can get full if you store loads of data (and I mean insane amounts of data here). With usual things you will never run into that limit but when I used it to store function traces of AMAI it did run full. That only happened after many thousands of entries in the gamecache though.
 
Level 2
Joined
Aug 24, 2004
Messages
11
Thanks for the clarification AlAndy. A hashtable does sound a lot more desirable than an array. From what I have read, the number of variables you can store is an array is rather large (8,192) so as far as space goes I don't think you're really limited. This is just random guessing, but I suspect the hashtable size is also 8,192. It only makes sense for the Blizzard programmers to use the same kind array that is already available. No use in reinventing the wheel, right?
 
Status
Not open for further replies.
Top