• 🏆 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!

[Solved] Is it safe to do this?

Status
Not open for further replies.
Level 7
Joined
Apr 27, 2011
Messages
272
Hey guys is it safe to do this (i mean the subtraction part)

JASS:
 function MEEP takes handle H, string Label, integer Data returns nothing
    call SaveInteger(MEEP,GetHandleId(H)-8191,StringHash(Label)-8191,Data)
 endfunction

my reason for subtracting 8191 is to save some space in the game.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
to save some space in the game.

Why not do GetHandleId(H) - GetHandleId(null) instead of 8191? The number produced by GetHandleId(H) is far larger than 8191. I think it's either 0x100000 or 0x10008.

Either way, you're not really speeding anything up by reducing that number. Hash-tables don't work like arrays, their indexes are not directly representative of how much memory you'll need to store that.

You don't necessarily have to remove the StringHash part; depends how you want to interface it.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
Trying to shrink values to store them into a hash table is a waste of time unless the value is somehow beyond 2^31 − 1 (which no native integer in JASS should be, whether it be rawcode or handle id).

The only excuse to "hash" stringhash is if you need to store it into an array, and the ASCII library does that quite well: http://www.hiveworkshop.com/forums/jass-functions-413/snippet-ascii-190746/
 
Status
Not open for further replies.
Top