• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Array

Status
Not open for further replies.

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
WC3 arrays are vectors (dynamic arrays) with an upperbound of 2^13 or 8192 indices.

Due to a save/load off by one error index 8191 does not save so data is lost during a save/load cycle. Index 0 is often forgotten due to GUI silliness. An array at maximum size (indexes 4096 or larger has been assigned a value) take up 32 KB of memory + additional JASS interpreter overhead.

Hundreds and possibly thousands of such arrays can be declared. Most of the time you will never need to use an array at maximum size anyway. The only problem with large numbers of arrays is it likely relates to inefficient code which may cause performance problems but that is by no direct cause of the arrays.

It should be noted that GUI will initialize each index of an array up to the given size parameter with the choosen value. This is done as part of the map initialization thread and so can and often does lead to a op limit thread crash of the initialization thread which literally means no triggers will work. For this reason under no circumstances should you make GUI arrays with 8191 size. Most primitive types can be left at size 1 thanks to their dynamic nature. Only complex types like timer arrays need initialization sizes as you cannot create timers dynamically without using JASS (even then I still recommend just using the JASS for it).
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
If you use index 8191 in a map then if the user saves and then loads using the inbuilt feature (often used in single player) the value stored in index 8191 is lost and some possibly different value will be there instead.

As I already said, there is little to no reason to design around using such large arrays for most purposes. Unless you plan to use a lot of advanced data structures that you know will reach large sizes you should never use index 8191 or even index 1000 for that mater.

If you are using an instance based system where by you define an index in a set of arrays as corresponding to an instance (occurrence) of some virtual object you should use some form of index recycling system to re-use indices that have been freed (discarded, not needed etc). Most common is a linked list, often composed from integer members of the array set for efficiency. Unless you instantiate (allocate, create etc) thousands of such instances, your array will stay within a bounded size viewable as a sort of active set based on the worst case instance number. For common instances like custom abilities this should usually not exceed the minimum size of JASS arrays (16 or something tiny).

If you do plan to use thousands of such instances than you can link arrays together with conditional statements to give a functional unit array of a larger size with a performance of logn when n is the number of 8192 sized arrays used. You could also use hashtables which provide an arbitrary mapping of 2 integers to a value to handle overflow but be aware hashtables do suffer from O(n) degradation when heavily populated (many thousand elements).
 
Status
Not open for further replies.
Top