1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Ride into the sunset with the 32nd Modeling Contest. The contest is optionally paired. Best of luck, people!
    Dismiss Notice
  4. This adventure has come to an end. Congratulate our heroes in the 16th Mini Mapping Contest Results.
    Dismiss Notice
  5. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  6. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] The advantages of game cache

Discussion in 'Triggers & Scripts' started by Frostilicus, Sep 17, 2004.

  1. Frostilicus

    Frostilicus

    Joined:
    Aug 24, 2004
    Messages:
    11
    Resources:
    0
    Resources:
    0
    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?
     
  2. udorim

    udorim

    Joined:
    Aug 28, 2004
    Messages:
    2
    Resources:
    0
    Resources:
    0
    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.
     
  3. AIAndy

    AIAndy

    Joined:
    Apr 13, 2004
    Messages:
    29
    Resources:
    0
    Resources:
    0
    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.
     
  4. Frostilicus

    Frostilicus

    Joined:
    Aug 24, 2004
    Messages:
    11
    Resources:
    0
    Resources:
    0
    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?