1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The raddest synthwave tracks were chosen - Check out our Music Contest #12 - Results and congratulate the winners!
    Dismiss Notice
  4. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  5. Travel to distant realms and encounter scenes unknown to the common folk. The Greatest of Adventures is upon us with the 8th Cinematic Contest. Join in on a fun ride.
    Dismiss Notice
  6. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  7. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  8. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  9. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    Dismiss Notice
  10. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

How to calculate instances?

Discussion in 'Triggers & Scripts' started by Krogoth, Oct 17, 2012.

  1. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    Code (vJASS):
    struct X[10000]
        integer a[2]
        integer b[5]
    endstruct

    Vexorian writes that there are 2000 instances.
    How?
     
  2. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    10,000 / 5 = 2,000

    The thing is that structs actually convert into global arrays. For example:
    Code (vJASS):
    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:
    Code (vJASS):
    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. :)
     
  3. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    :O

    Thanks!

    edit
    This makes everything clear.
    I just thought size should be total. =]