Hashtables

Tar-Quaeron

New Member
Reaction score
0
Does anyone know how much RAM a global hashtable takes up? Because if it's an array representing 2.1 billion (about the possible range of an integer) * 2.1 billion handles in a table, that's 4*10^18*4 bytes (because the hashtable would store a pointer to the handle in question, i.e. an integer?), i.e. A million terabytes? Yeah, so I guess there's a hashing function (wikipedia) which, from the value you give to the parent and child key assigns a particular index in the array?

I'm just worried, that as I get all excited about hashtables and start using them a lot, the map will take up a lot of memory while it's running.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Nope, hashtables are memory leak free.
Example you stored a unit in hashtable, then the unit is removed, hashtable reference no long hold that unit anymore.
Hashtables are nothing wrong, but very useful indeed.
 

Tar-Quaeron

New Member
Reaction score
0
Oh okay, yeah, I was wondering that too, if after use you had to be like:
call SaveEffectHandle(bla, bla, bla, null). Still, they take up RAM, just like any other variable. Especially if they're global, that memory is never freed while the map runs. For example a global integer array in JASS would take up 8192 * 4 bytes of RAM, i.e. 32 kb, which is negligible, even on 300 MB of RAM as on my computer. Yeah, I'm worried about hashtables though, because just now as I was running my map, it crashed, and I got the message that there wasn't enough memory to work with. Sure, my computer is old, and there were other programs running. But this has always intrigued me, how do Hashtables work in JASS, or rather in C++ as Blizzard designed it for warcraft 3, as the JASS code is just compiled into already existing C++ right?
 

the Immortal

I know, I know...
Reaction score
51
Read on them?

JASS may have nothing to do with Cpp. For example the arrays we use in JASS are indeed dynamic, but they seem not to be as C++'s vectors (did a small test somewhere, gonna find it if u want).

First, hashtables use (Surprise!) a hash function on the keys and then store the results into an array. But then we can have different keys with the same hashed value. The most simple workaround would be to store colliding keys in a data structure like linked list or a BST. Optionally they may get dynamically resized when the load factor becomes too big.

And as I wouldn't expect anything too complicated be built for war3's engine (considering it was N-years-old when hashtables came out), I'd say their implementation is something along these lines.

In short - they (ht) should allocate one (two, three) arrays' space and then extend only by amount proportional to the elements you put inside. Memory outage (i.e. crash) has happened even to an old server machine of ours w/ 6gb RAM while playing War3 with way too much background programs and disabled swapfile.
 

Bribe

vJass errors are legion
Reaction score
67
Hashtables hold 2 ^ 32 values. Integers in JASS, last I read, range from - 2 ^ 31 to 2 ^ 31.

If you need to save a ton of values in hashtables and never deallocate them, you have got to be out of your mind. I built a form of time-machine in JASS using hashtable to simulate a 3-D array, but I also have it erase data older than, say, 20 seconds.

[ljass]call RemoveSavedReal(hashtable, integer, integer)[/ljass]
[ljass]call FlushChildHashtable(hashtable, integer)[/ljass]
 

Tar-Quaeron

New Member
Reaction score
0
Yeah, ok, I see. So it's really important, to save memory usage, to call RemoveSavedReal/RemoveSavedHandle/FlushTable after use, else the hashing function will have to call another function which reallocates the data to another index, so as to avoid collision.

@Bribe, in the jass manual, section types it says integers range from -2.147 * 10^9 to 2.147 * 10^9. Float, i.e. real is something like 10^31.

Thx for your answers.
 

Bribe

vJass errors are legion
Reaction score
67
Well, rawcodes produce numbers in the trillions, so you know integers have a huge capacity.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
Integers (in C) are actually rather small, but unsigned integers / (unsigned) longs are pretty big (in terms of the max value), if I remember correctly.
 

Bribe

vJass errors are legion
Reaction score
67
I like that Python 3.0 treats integers and longs the same.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
It's too early to be using 3.0, at least in production environments.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top