Snippet Hashtable Alarm

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
///////////////////////////////////////////////
//          Hashtable Alarm ~ v1.0.1 ~
//           by kingking
//
//  ~ It is known Blizzard made the hashtable 
//    type has a limit of 256. In order to 
//    prevent hitting the limitation, this 
//    library can tell the map makers if their 
//    map is hitting the limitation.
//
//  ~ It can also acts as the hashtable leak
//    checker.
//  ~ Basically a map does not requires so
//    much of hashtables. But if you are
//    spamming InitHashtable, then it
//    may hit the limitation.
//  
//  How to use ?
//  ~ Test your map in debug mode.
//  ~ See whether it will shows the warning
//  message or not.
//
//  Requires : Lastest version of Jasshelper.
//////////////////////////////////////////////
library HashtableAlarm

    globals
        private constant integer HASHTABLE_LIMIT = 256
        private integer HashtableCount = 0
    endglobals
    
    private function Increment takes nothing returns nothing
        set HashtableCount = HashtableCount + 1
        if HashtableCount >= HASHTABLE_LIMIT then
            call BJDebugMsg("Hashtable limit is reached, null hashtable will be returned!")
        endif
    endfunction
    
    debug hook InitHashtable Increment
    
    private function Decrement takes hashtable hasht returns nothing
        call SaveInteger(hasht,0,0,1)//Check whether the hashtable is flushed or not.
        if LoadInteger(hasht,0,0) == 1 then
            set HashtableCount = HashtableCount - 1
        endif
    endfunction
    
    debug hook FlushParentHashtable Decrement
endlibrary
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Can you please tell me: When will people EVER hit the 256 limit of hashtables? If you do, then you are doing something TERRIBLY wrong.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
~ Basically a map does not requires so much of hashtables. But if you are spamming InitHashtable, then it may hit the limitation.
 

Romek

Super Moderator
Reaction score
963
> I think this is quite good, really. Why wouldn't you use this? It only runs in debug mode... right?
I disagree. It's a piece of code that'll never be used, and two functions that'll never be called.
Judging from what you said, it seems as though people would be able to submit any random (useless, unneeded) debug libraries, that "only run in debug mode" anyway. :p
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Basically a map does not requires so
// much of hashtables. But if you are
// spamming InitHashtable, then it
// may hit the limitation.

The problem is that :
If you're spamming InitHashtable, you're already wrong ...
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
I say this is a good idea. A lot of systems use hashtable, so it's a lot easier to hit the limit.

Also, add a function to check how many hashtables there currently are with a command.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Also, add a function to check how many hashtables there currently are with a command.
Okay.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
If you're spamming InitHashtable, you're already wrong ...
So, this library can make users realize that he/she is doing wrong with hashtable.
 

the Immortal

I know, I know...
Reaction score
51
Utterly pointless in my humble opinion.

No one should create dynamically hashtables in a system. That would mean he needs to assign several values to all pairs of indexes in the range -2^16 till 2^16 more than once. And that is both implausible and idiotic (Hello there, struct usage? 2(3)D abstraction?)

No one should have 256 spells/systems each with a hashtable if they have the slightest clue of what they are doing. And if they do, believe me, they won't use this system. And even if they do, they'll most probably be unable to fix it.

And, finally, one tutorial pointing out how hashtable usage can be optimized / limited to minimum in favour of indexing and/or Table would be much, much better, although still not needed, I'd say.

cent-and-a-half, thx
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Er.... Am I failed to explain the stuffs which make you all keep repeating same stuffs?
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
I think everyone is missing the point.

We now know that there are 255 (starting at 0) hashtables allow. Does this change anything? Not really.
But these systems are useful in the way handle counting systems are useful. You don't absolutely need to know if you have X amount if handles in your map, but you'll go right ahead and import that system to check them, because you feel you need to.

You don't need to know how many hashtables your using, but it could prove to be useful to some people.
 

Deaod

Member
Reaction score
6
Did you ever create even ONE hashtable inside a map (you yourself, that is, not by importing some library)? I didnt, and i dont see the need to. Table is far more than enough for my purposes. If you have a use for hashtables that is NOT covered by Table, tell me.

Is it likely that 255 libraries will create hashtables themselves, and you have all of them inside one map? No, rather unlikely, i think.

So, if you wont reach 255 hashtables without you writing bad code, why dont you write a tutorial about how to NOT use hashtables in your code and instead use Table, and spread the word about not using hashtables lightheartedly? Seems like a better idea than having this piece lying around and rot in a database.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
Again, your missing the point.

Just because YOU don't have a need for it doesn't mean OTHERS won't.

Edit:

After thinking, I'm going to say this system itself is useless. The concept is sound, but the system isn't anything someone can't do on they're own.

You need a lot more work on this, than just two functions and hooks.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Is it likely that 255 libraries will create hashtables themselves, and you have all of them inside one map? No, rather unlikely, i think.

So, if you wont reach 255 hashtables without you writing bad code, why dont you write a tutorial about how to NOT use hashtables in your code and instead use Table, and spread the word about not using hashtables lightheartedly?
I agree.

>If you have a use for hashtables that is NOT covered by Table, tell me.
The way SpellStruct uses them.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Using an hashtable as an unlimited 2D array is sometimes handy, and for that Table is bad (in case you care about efficiency).
But anyway unless you create dynamically hashtables (which is silly) you won't have any problem.

If this script is approved, do the same with gamecache ...
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Hmm ... I thought about it again and came to the conclusion, that, possibly, this snippet is not as useless as I thought it would be.

The thing is, that you can use [ljass]SaveHashtableHandle[/ljass] and [ljass]LoadHashtableHandle[/ljass], such as [ljass]GetHandleId(somehash)[/ljass] to create 3-dimensional and even 4-dimensional arrays. ... though, obviously, because of the 256 instance limit, that wouldn't make much sense.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
A 4D array would be sexy, though there isn't any need for it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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