• 🏆 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] Array Struct Allocation/Assignment of Keyword "This"

Status
Not open for further replies.
Level 2
Joined
Apr 7, 2008
Messages
19
Hello, I am using an array struct. Let's call it ExAS for the discussion.

When I call ExAS.create(), I see that the definition of create() typically involves assigning "this" to an integer.

So we see something like this:

JASS:
local ExAS this  = Index

and "Index" will be an integer for the index of a stack.

Now my question arises: if I have an arbitrary array struct and I'm using AutoIndex's GetUnitId() function, and I use

JASS:
local ExAS this = GetUnitId(someUnit)

is there some significant memory usage that results from assigning index 8000 with no data in all the previous 8000 elements, and therefore I should use the array struct in a more controlled fashion?

Or is using the array struct like a hashmap (with GetUnitId() as the hash function) practical and safe? (Does WC3 allocate memory for all ~8190 elements of the array when I declare an array at all? In this case, it seems like there would be no difference between trying to formalize the structure of an ordinary array and simply using array struct as though it were a hashmap.)

I feel that if I could simply use an array struct like a hashmap from unit Id to struct instance then my life would be very easy. Then it would be easily to arbitrarily access the array struct ExAS and pull out any unit that I might want to check out.

EDIT: By "hashmap" I really just mean any sort of "dictionary" or "map" or "associative array" data structure.
 
Last edited by a moderator:

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
is there some significant memory usage that results from assigning index 8000 with no data in all the previous 8000 elements, and therefore I should use the array struct in a more controlled fashion?
Each member can use up to 8192*4 bytes with some little overhead. More specifically each array can take at most 32 kilobytes. You can get 32 such arrays per megabyte of memory and Warcraft III is limited to ~2 GB of memory. You will need a lot of such arrays to be a concern.

(Does WC3 allocate memory for all ~8190 elements of the array when I declare an array at all? In this case, it seems like there would be no difference between trying to formalize the structure of an ordinary array and simply using array struct as though it were a hashmap.)
They are dynamic arrays which are expanded as required. I forget the minimum size but expansion occurs in powers of two if I recall.

I feel that if I could simply use an array struct like a hashmap from unit Id to struct instance then my life would be very easy. Then it would be easily to arbitrarily access the array struct ExAS and pull out any unit that I might want to check out.
This is how a lot of GUI systems and abilities work. They use a unit index value as an index into an array.
 
Status
Not open for further replies.
Top