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.
  • 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 The Helper:
    Happy Thursday!
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top