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

How to calculate instances?

Status
Not open for further replies.
10,000 / 5 = 2,000

The thing is that structs actually convert into global arrays. For example:
JASS:
struct A
    real b
endstruct

Even though it is not listed as an array, real b is actually an array variable. When jasshelper converts vJASS to regular JASS, it does that to simulate struct instances. Whereas it seems that the variable is associated with a struct instance, it is actually just associated with an integer that acts as the index. However, you don't need to worry too much about understanding that at the moment. All you need to know is that struct members are eventually converted into arrays.

Therefore, when you declare an array variable as a struct member, it has to do some 2D interfacing. That's why if you have an integer array in a struct, you have to declare a size. The size limits how many total instances you can have for the struct. The general rule is that the variable with the highest array size will be the limiter. So:
JASS:
struct X
    integer a[50]
    integer b[32]
endstruct
The variable a will limit X to 8192/50 = ~163 instances.

Generally, try to keep the indices to a reasonable value. Don't make it 4192 and extend the struct to 40,000 instances just as insurance. Remember that jasshelper converts vJASS to regular JASS, so having extended struct instances and higher indexes will end up adding quite a bit of code. :)
 
Status
Not open for further replies.
Top