• 🏆 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] Getting Array Length

Status
Not open for further replies.
Level 5
Joined
Jan 19, 2018
Messages
126
Hello Hive,
Quick question, is there a way to grab the current length of an array using GUI?

I need it in order to finish my custom item table trigger system for bonus loot dropped by creeps.
It works like this:

Creep dies
20% chance:
create 1 BonusItem[Math:random number between 0 and array.length] at position of dying unit

So a random item in the array will be chosen but if I change the size of the array I have to remember to change the trigger to reflect that so I'm hoping there is a way to grab the array length as to keep it dynamic so I don't have to keep doing this.

Thanks in advance.
 
Level 5
Joined
Jan 19, 2018
Messages
126
Not possible.

array.length exist in any decent programming language... but not jass and GUI
Though you could write a wrapper (v)jass and use custom scripts.

In pure GUI though, not going to happen. You need to make a separate variable to keep track on the size.

Awesome,
well then I'll just hard code those values I doubt I'll be changing them much anyway.
Thanks for the quick response!
I'll change the thread to solved.
 
Just a short reminder, the array length is actually always statically 8192, or in new patch 1.29 then 32768. What bothers us is the max index of assigned elements in the array. Because I was a bit uncertain on first look.

Counting with an extra variable seems fine and a bit better than hard coding.

Technically the size of a JASS array depends on the largest index.

JASS:
set arr[1] = "test" // array is size 1
set arr[8000] = "another test" // array is now size 8k
But it's not really relevant to the OP. If you want to dynamically check the size of an array you will have to store highest index each time you assign a new value which causes unnecessary overhead.
 
Level 5
Joined
Jan 19, 2018
Messages
126
I am pretty sure he does not mean available indexes, but rather how many values are stored in the array.
Under the assumption that there are no empty ones.
Yes, that is correct.
Just a short reminder, the array length is actually always statically 8192, or in new patch 1.29 then 32768. What bothers us is the max index of assigned elements in the array. Because I was a bit uncertain on first look.

Counting with an extra variable seems fine and a bit better than hard coding.
With the way I made this system I'm not even sure how I would use a counter to find the size of the array.
Here are my triggers that make up my bonus loot system:
  • Item Table Initialization
    • Events
    • Conditions
    • Actions
      • -------- -------------------------------------- --------
      • -------- Low Grade Consumables --------
      • -------- -------------------------------------- --------
      • Set LowGradeConsumableItem[0] = Healing Salve
      • Set LowGradeConsumableItem[1] = Lesser Clarity Potion
      • Set LowGradeConsumableItem[2] = Potion of Invisibility
      • Set LowGradeConsumableItem[3] = Vial of Healing
      • Set LowGradeConsumableItem[4] = Vial of Mana
      • Set LowGradeConsumableItem[5] = Vial of Invulnerability
      • Set LowGradeConsumableItem[6] = Potion of Healing
      • Set LowGradeConsumableItem[7] = Potion of Mana
      • Set LowGradeConsumableItem[8] = Replenishment Potion
      • Set LowGradeConsumableItem[9] = Scroll of Speed
      • -------- ------------------------------------- --------
      • -------- Mid Grade Consumables --------
      • -------- ------------------------------------- --------
      • Set MidGradeConsumableItem[0] = Potion of Healing
      • Set MidGradeConsumableItem[1] = Potion of Healing
      • Set MidGradeConsumableItem[2] = Potion of Mana
      • Set MidGradeConsumableItem[3] = Potion of Mana
      • Set MidGradeConsumableItem[4] = |cff1eff00Flask of Exceptional Healing|r
      • Set MidGradeConsumableItem[5] = |cff1eff00Flask of Greater Mana|r
      • Set MidGradeConsumableItem[6] = |cff1eff00Potion of Restoration|r
      • Set MidGradeConsumableItem[7] = |cff1eff00Health Stone|r
      • Set MidGradeConsumableItem[8] = |cff1eff00Mana Stone|r
      • Set MidGradeConsumableItem[9] = Potion of Invulnerability
      • Set MidGradeConsumableItem[10] = Vampiric Potion
      • Set MidGradeConsumableItem[11] = |cff1eff00Scroll of Healing|r
      • Set MidGradeConsumableItem[12] = |cff1eff00Scroll of Mana|r
      • Set MidGradeConsumableItem[13] = |cff1eff00Scroll of Protection|r
      • -------- --------------------------------------- --------
      • -------- High Grade Consumables --------
      • -------- --------------------------------------- --------
      • Set HighGradeConsumableItem[0] = |cff0070ddElixir of Spirited Mana|r
      • Set HighGradeConsumableItem[1] = |cff0070ddElixir of Spirited Mana|r
      • Set HighGradeConsumableItem[2] = |cff0070ddElixir of Spirited Mana|r
      • Set HighGradeConsumableItem[3] = |cff0070ddElixir of Zealous Healing|r
      • Set HighGradeConsumableItem[4] = |cff0070ddElixir of Zealous Healing|r
      • Set HighGradeConsumableItem[5] = |cff0070ddElixir of Zealous Healing|r
      • Set HighGradeConsumableItem[6] = |cff0070ddFlask of Powerful Restoration|r
      • Set HighGradeConsumableItem[7] = |cff0070ddFlask of Powerful Restoration|r
      • Set HighGradeConsumableItem[8] = |cffa46331Nesquik|r
      • Set HighGradeConsumableItem[9] = |cff0070ddLovely Phial|r
      • Set HighGradeConsumableItem[10] = |cffa335eeElixir of Mighty Restoration|r
      • -------- --------------------------------------- --------
      • -------- Low Grade Charged Items --------
      • -------- --------------------------------------- --------
      • Set LowGradeChargedItem[0] = Wand of Illusion
      • Set LowGradeChargedItem[1] = Wand of Lightning Shield
      • Set LowGradeChargedItem[2] = Sentry Wards
      • -------- -------------------------------------- --------
      • -------- Mid Grade Charged Items --------
      • -------- -------------------------------------- --------
      • Set MidGradeChargedItem[0] = Fel Token
      • Set MidGradeChargedItem[1] = Red Drake Egg
      • Set MidGradeChargedItem[2] = Stone Token
      • -------- --------------------------------------- --------
      • -------- High Grade Charged Items --------
      • -------- --------------------------------------- --------
      • Set HighGradeChargedItem[0] = |cff1eff00Healing Wards|r
      • Set HighGradeChargedItem[1] = |cff1eff00Ankh of Reincarnation|r
      • Set HighGradeChargedItem[2] = |cff1eff00Ice Shard|r
      • Set HighGradeChargedItem[3] = |cff1eff00Demonic Figurine|r
      • Set HighGradeChargedItem[4] = |cff1eff00Relic of the Wild|r
      • -------- --------------------------------- --------
      • -------- Low Grade Power Ups --------
      • -------- --------------------------------- --------
      • Set LowGradePowerUp[0] = Tome of Agility
      • Set LowGradePowerUp[1] = Tome of Intelligence
      • Set LowGradePowerUp[2] = Tome of Strength
      • Set LowGradePowerUp[3] = Manual of Health
      • -------- --------------------------------- --------
      • -------- Mid Grade Power Ups --------
      • -------- --------------------------------- --------
      • Set MidGradePowerUp[0] = |cff1eff00Tome of Dexterity|r
      • Set MidGradePowerUp[1] = |cff1eff00Tome of Intuition|r
      • Set MidGradePowerUp[2] = |cff1eff00Tome of Intuition|r
      • Set MidGradePowerUp[3] = |cff1eff00Tome of Knowledge|r
      • Set MidGradePowerUp[4] = |cff1eff00Manual of Life|r
      • -------- --------------------------------- --------
      • -------- High Grade Power Ups --------
      • -------- --------------------------------- --------
      • Set HighGradePowerUp[0] = |cff0070ddTome of Brilliance|r
      • Set HighGradePowerUp[1] = |cff0070ddTome of Finesse|r
      • Set HighGradePowerUp[2] = |cff0070ddTome of Vigor|r
      • Set HighGradePowerUp[3] = |cff0070ddTome of Wisdom|r
      • Set HighGradePowerUp[4] = |cff0070ddManual of Vitality|r
      • -------- -------------------------- --------
      • -------- Low Grade Runes --------
      • -------- -------------------------- --------
      • Set LowGradeRune[0] = Rune of Lesser Healing
      • Set LowGradeRune[1] = Rune of Lesser Healing
      • Set LowGradeRune[2] = Rune of Lesser Healing
      • Set LowGradeRune[3] = Rune of Lesser Mana
      • Set LowGradeRune[4] = Rune of Lesser Mana
      • Set LowGradeRune[5] = Rune of Lesser Mana
      • Set LowGradeRune[6] = Rune of Lesser Resurrection
      • -------- -------------------------- --------
      • -------- Mid Grade Runes --------
      • -------- -------------------------- --------
      • Set MidGradeRune[0] = Rune of Healing
      • Set MidGradeRune[1] = Rune of Healing
      • Set MidGradeRune[2] = Rune of Healing
      • Set MidGradeRune[3] = Rune of Mana
      • Set MidGradeRune[4] = Rune of Mana
      • Set MidGradeRune[5] = Rune of Mana
      • Set MidGradeRune[6] = Rune of Armor
      • Set MidGradeRune[7] = Rune of Armor
      • Set MidGradeRune[8] = Rune of Resurrection
      • -------- --------------------------- --------
      • -------- High Grade Runes --------
      • -------- --------------------------- --------
      • Set HighGradeRune[0] = |cff1eff00Rune of Greater Healing|r
      • Set HighGradeRune[1] = |cff1eff00Rune of Greater Healing|r
      • Set HighGradeRune[2] = |cff1eff00Rune of Greater Healing|r
      • Set HighGradeRune[3] = |cff1eff00Rune of Greater Mana|r
      • Set HighGradeRune[4] = |cff1eff00Rune of Greater Mana|r
      • Set HighGradeRune[5] = |cff1eff00Rune of Greater Mana|r
      • Set HighGradeRune[6] = Rune of Armor
      • Set HighGradeRune[7] = Rune of Armor
      • Set HighGradeRune[8] = |cff1eff00Rune of Restoration|r
      • Set HighGradeRune[9] = |cff1eff00Rune of Greater Resurrection|r
      • -------- ------------------------------------------ --------
      • -------- Low Grade Permanent Items --------
      • -------- ------------------------------------------ --------
      • Set LowGradePermanentItem[0] = Claws of Attacking
      • Set LowGradePermanentItem[1] = Ring of Superiority
      • Set LowGradePermanentItem[2] = Gauntlets of Ogre Strength
      • Set LowGradePermanentItem[3] = Mantle of Intelligence
      • Set LowGradePermanentItem[4] = Slippers of Agility
      • Set LowGradePermanentItem[5] = Circlet of Nobility
      • Set LowGradePermanentItem[6] = Ring of Protection
      • Set LowGradePermanentItem[7] = Gloves of Haste
      • Set LowGradePermanentItem[8] = Circlet of Nobility
      • -------- ----------------------------------------- --------
      • -------- Mid Grade Permanent Items --------
      • -------- ----------------------------------------- --------
      • Set MidGradePermanentItem[0] = |cff1eff00Boots of Speed|r
      • Set MidGradePermanentItem[1] = |cff1eff00Claws of Ravaging|r
      • Set MidGradePermanentItem[2] = |cff1eff00Pendant of Energy|r
      • Set MidGradePermanentItem[3] = |cff1eff00Periapt of Vitality|r
      • Set MidGradePermanentItem[4] = |cff1eff00Ring of Defense|r
      • Set MidGradePermanentItem[5] = |cff1eff00Sobi Mask|r
      • Set MidGradePermanentItem[6] = |cff1eff00Belt of Giant Strength|r
      • Set MidGradePermanentItem[7] = |cff1eff00Boots of Quel'Thalas|r
      • Set MidGradePermanentItem[8] = |cff1eff00Robe of the Magi|r
      • -------- ---------------------------------------------------------- --------
      • -------- High Grade Permanent Items & Artifacts --------
      • -------- ---------------------------------------------------------- --------
      • Set HighGradePermanentItem[0] = |cff1eff00Claws of Frenzying|r
      • Set HighGradePermanentItem[1] = |cff1eff00Claws of Frenzying|r
      • Set HighGradePermanentItem[2] = |cff1eff00Claws of Frenzying|r
      • Set HighGradePermanentItem[3] = |cff1eff00Helm of Valor|r
      • Set HighGradePermanentItem[4] = |cff1eff00Helm of Valor|r
      • Set HighGradePermanentItem[5] = |cff1eff00Helm of Valor|r
      • Set HighGradePermanentItem[6] = |cff1eff00Hood of Cunning|r
      • Set HighGradePermanentItem[7] = |cff1eff00Hood of Cunning|r
      • Set HighGradePermanentItem[8] = |cff1eff00Hood of Cunning|r
      • Set HighGradePermanentItem[9] = |cff1eff00Medallion of Courage|r
      • Set HighGradePermanentItem[10] = |cff1eff00Medallion of Courage|r
      • Set HighGradePermanentItem[11] = |cff1eff00Medallion of Courage|r
      • Set HighGradePermanentItem[12] = |cff0070ddClaws of Rampaging|r
      • Set HighGradePermanentItem[13] = |cff0070ddClaws of Rampaging|r
      • Set HighGradePermanentItem[14] = |cff0070ddRing of Wardship|r
      • Set HighGradePermanentItem[15] = |cff0070ddRing of Wardship|r
      • Set HighGradePermanentItem[16] = |cff0070ddKhadgar's Gem of Health|r
      • Set HighGradePermanentItem[17] = |cff0070ddKhadgar's Gem of Health|r
      • Set HighGradePermanentItem[18] = |cff0070ddPendant of Mana|r
      • Set HighGradePermanentItem[19] = |cff0070ddPendant of Mana|r
      • Set HighGradePermanentItem[20] = |cff0070ddCrown of Kings|r
      • Set HighGradePermanentItem[21] = |cff0070ddCrown of Kings|r
      • Set HighGradePermanentItem[22] = |cff0070ddMask of Death|r
      • Set HighGradePermanentItem[23] = |cff0070ddMask of Death|r
      • Set HighGradePermanentItem[24] = |cffa335eeClaws of Annihilation|r
      • Set HighGradePermanentItem[25] = |cffa335eeRing of Preservation|r
      • Set HighGradePermanentItem[26] = |cffa335eeCrown of Emperors|r
      • Set HighGradePermanentItem[27] = |cffa335eeMask of Devastation|r
      • -------- ---------------------------------------------- --------
      • -------- Duskwood Cemetery Boss Item --------
      • -------- ---------------------------------------------- --------
      • Set MorLadimItem[0] = |cffa335eeMor'Ladim's Corrupted Helm|r
      • Set MorLadimItem[1] = |cffa335eeMor'Ladim's Corrupted Shield|r
      • Set MorLadimItem[2] = |cffa335eeMor'Ladim's Corrupted Sword|r
      • -------- --------------------------------------------- --------
      • -------- Throne of Kil'jaeden Boss Item --------
      • -------- --------------------------------------------- --------
      • Set KezzakItem[0] = |cffa335eeAmulet of the Burning Legion|r
      • Set KezzakItem[1] = |cffa335eeClaws of the Burning Raider|r
      • Set KezzakItem[2] = |cffa335eeDiamond of Insight|r
      • -------- ------------------------------------------ --------
      • -------- Abyssal Maw First Boss Item --------
      • -------- ------------------------------------------ --------
      • Set VezaxItem[0] = |cffa335eeBlade of Betrayal|r
      • Set VezaxItem[1] = |cffa335eeHeart of Corruption|r
      • Set VezaxItem[2] = |cffa335eeRelic of Deceit|r
      • -------- ------------------------------------------- --------
      • -------- Abyssal Maw Final Boss Item --------
      • -------- ------------------------------------------- --------
      • Set TestimonyItem[0] = |cffff8c00Kaaxth Shuul, Shawl of a Thousand Deaths|r
      • Set TestimonyItem[1] = |cffff8000An'shel, Ring of the Void|r
  • World Drops
    • Events
      • Unit - A unit Dies
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • ((Owner of (Dying unit)) Equal to Neutral Hostile) and ((Instance Zone <gen> contains (Dying unit)) Equal to False)
    • Actions
      • Set LootChance = (Random integer number between 1 and 100)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Level of (Dying unit)) Greater than or equal to 1) and ((Level of (Dying unit)) Less than or equal to 3)
          • (LootChance Greater than or equal to 1) and (LootChance Less than or equal to 20)
        • Then - Actions
          • Floating Text - Create floating text that reads Bonus Loot! at (Position of (Dying unit)) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
          • Floating Text - Set the velocity of (Last created floating text) to 32.00 towards 90.00 degrees
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Change the lifespan of (Last created floating text) to 2.00 seconds
          • Floating Text - Change the fading age of (Last created floating text) to 0.50 seconds
          • Set LootTypeRoll = (Random integer number between 1 and 4)
          • If (LootTypeRoll Equal to 1) then do (Item - Create LowGradeConsumableItem[(Random integer number between 0 and 9)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 2) then do (Item - Create LowGradeChargedItem[(Random integer number between 0 and 2)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 3) then do (Item - Create LowGradePowerUp[(Random integer number between 0 and 3)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 4) then do (Item - Create LowGradePermanentItem[(Random integer number between 0 and 8)] at (Position of (Dying unit))) else do (Do nothing)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Level of (Dying unit)) Greater than or equal to 4) and ((Level of (Dying unit)) Less than or equal to 6)
          • (LootChance Greater than or equal to 1) and (LootChance Less than or equal to 25)
        • Then - Actions
          • Floating Text - Create floating text that reads Bonus Loot! at (Position of (Dying unit)) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
          • Floating Text - Set the velocity of (Last created floating text) to 32.00 towards 90.00 degrees
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Change the lifespan of (Last created floating text) to 2.00 seconds
          • Floating Text - Change the fading age of (Last created floating text) to 0.50 seconds
          • Set LootTypeRoll = (Random integer number between 1 and 4)
          • If (LootTypeRoll Equal to 1) then do (Item - Create MidGradeConsumableItem[(Random integer number between 0 and 13)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 2) then do (Item - Create MidGradeChargedItem[(Random integer number between 0 and 2)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 3) then do (Item - Create MidGradePowerUp[(Random integer number between 0 and 4)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 4) then do (Item - Create MidGradePermanentItem[(Random integer number between 0 and 8)] at (Position of (Dying unit))) else do (Do nothing)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Level of (Dying unit)) Greater than or equal to 7) and ((Level of (Dying unit)) Less than or equal to 10)
          • (LootChance Greater than or equal to 1) and (LootChance Less than or equal to 33)
        • Then - Actions
          • Floating Text - Create floating text that reads Bonus Loot! at (Position of (Dying unit)) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
          • Floating Text - Set the velocity of (Last created floating text) to 32.00 towards 90.00 degrees
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Change the lifespan of (Last created floating text) to 2.00 seconds
          • Floating Text - Change the fading age of (Last created floating text) to 0.50 seconds
          • Set LootTypeRoll = (Random integer number between 1 and 4)
          • If (LootTypeRoll Equal to 1) then do (Item - Create HighGradeConsumableItem[(Random integer number between 0 and 10)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 2) then do (Item - Create HighGradeChargedItem[(Random integer number between 0 and 4)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 3) then do (Item - Create HighGradePowerUp[(Random integer number between 0 and 4)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 4) then do (Item - Create HighGradePermanentItem[(Random integer number between 0 and 27)] at (Position of (Dying unit))) else do (Do nothing)
        • Else - Actions
Here's what its doing:
Creeps level 1 - 3 have a 20% chance to drop low grade bonus loot upon death.
Creeps level 4 - 6 have a 25% chance to drop mid grade bonus loot upon death.
Creeps level 7 - 10 have a 33% chance to drop high grade bonus loot upon death.
Loot types:
1 = Consumable
2 = Charged
3 = Power Up
4 = Permanent & Artifact

If it generates more overhead to use counters then it would seem counter productive to use variable counters rather than hard coding it,
especially since this array is defined at the start of the game and does not change ingame.
It was just for the sake of pure laziness that I wanted to make the loot system more dynamic so I have less revisions to do if I add a new
item to the system.
 
Last edited:
The overhead is ok, just make a variable "MaxBonus" or so, and assign it in the config trigger with the right value. Later, when adding new ones, you don't have to go into your codes anymore, but just modify the variable.


@TriggerHappy not sure we're maybe not align with lingo, but for me the array length is always static but is also not the same as highest assigned index. That way, I could dynamicaly increase and decrease the array size, which seems not very right. In C-like languages I know we can not really re-allocate memory dynamically, but just maybe re-locate it, meaning deleating the whole thing, and allocating it again in a re-sized form, which then would result in true new array length.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
array.length exist in any decent programming language...
Nope a lot of languages lack them. Technically arrays have no length as they memory lookup instructions. The logical length of the array is however big the space one has allocated for it is. As soon as one assigns a size property to an array that becomes an extra piece of data to store which can add considerable overhead for lots of small arrays. Some modern compilers that know the length of arrays at compile time will optimize out such length property with constants.

Generally only safe languages like C# and Java give arrays an automatic length. They also perform bounds checks on access and assignment. All of these add overhead, but such overhead is often worth while as it makes them immune to typical buffer overrun problems.

C++ offers vector and other classes which provide functionality similar to a managed array. Again there will be overhead associated with this both computationally and memory.
create 1 BonusItem[Math:random number between 0 and array.length] at position of dying unit
Since arrays in WC3 can always be considered as empty 32,768 element banks one has to manually track the number of elements one stores in them. Hence when you are filling the array with data you should also be counting how many elements you added to it. Generally the result is closer to a typical collection API than an actual array.
Technically the size of a JASS array depends on the largest index.
I recall people posting in the past that they are dynamically expanded by powers of 2. Hence even knowing the maximum used index will still not reveal the actual underlying size, unless maybe some maths were performed on it. However why one would ever need to know this is beyond me.
With the way I made this system I'm not even sure how I would use a counter to find the size of the array.
Instead of hard coding array indicies when defining the data, dynamically code them. For example...
Set LowGradeConsumableItem[0] = Healing Salve
Set LowGradeConsumableItem[1] = Lesser Clarity Potion​
Becomes...
Set LowGradeConsumableItemCount = 0
Set LowGradeConsumableItem[LowGradeConsumableItemCount] = Healing Salve
Set LowGradeConsumableItemCount = LowGradeConsumableItemCount + 1
Set LowGradeConsumableItem[LowGradeConsumableItemCount] = Lesser Clarity Potion
Set LowGradeConsumableItemCount = LowGradeConsumableItemCount + 1
Not only is this more maintainable since one can modify ordering with trivial effort, but it also leaves the count of elements in LowGradeConsumableItemCount which one can use at a later time, eg to get a random element from the list.
especially since this array is defined at the start of the game and does not change ingame.
Except they do change in game. JASS arrays (used by GUI) are dynamically expanding storage spaces that can expand to a maximum size of 32,768.

Arrays are not lists. What you want is a list of elements. A list has an element count. One has to explicitly program list like mechanics in JASS, like shown above.
That way, I could dynamicaly increase and decrease the array size, which seems not very right.
Once JASS arrays are expanded they will never decrease in size. This is the result of there being no API to instruct the virtual machine that an array index is no longer required. As far as the programmer is concerned they are always arrays with a size of 32,768, although the backing allocated memory will be smaller than that unless the larger index numbers are used.
In C-like languages I know we can not really re-allocate memory dynamically, but just maybe re-locate it, meaning deleating the whole thing, and allocating it again in a re-sized form, which then would result in true new array length.
C memory API supports memory resizing. If it ever resizes the allocated memory is another question and one that I am sure is implementation specific.

JASS arrays might attempt a resize, however it is unlikely to succeed in most memory allocation approaches. Hence it is most likely that the memory resize that occurs when JASS arrays dynamically expand starts off by allocating new memory somewhere else, copies the contents of the old memory across and then frees the old memory. This overhead can be considered trivial as it will occur only once and involve at most 32,768 * 4 bytes.
 
"allocating new memory somewhere else, and free old memory" is basically what I meant with
we can not really re-allocate memory dynamically, but just maybe re-locate it, meaning deleating the whole thing, and allocating it again in a re-sized form, which then would result in true new array length.

but, so you mean they re-locate it with indices of power of 2? May I ask how you assume they integrated that logics in background, and not just initialy declare the array with max size from begining?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
but, so you mean they re-locate it with indices of power of 2? May I ask how you assume they integrated that logics in background, and not just initialy declare the array with max size from begining?
Various people in the past reverse engineered it I assume. It also makes sense seeing how JASS is a virtual machine so has to perform array bound checks for security anyway.

One can likely measure a noticeable memory increase to from this happening, if it is true. Declare 1,000 arrays and then set the last index (8191 in 1.28.5 or 32767 in 1.29) to a value. If they do dynamically resize one should see the Warcraft III process shoot up a few megabytes once when it occurs.
 
Level 5
Joined
Jan 19, 2018
Messages
126
Since arrays in WC3 can always be considered as empty 32,768 element banks one has to manually track the number of elements one stores in them. Hence when you are filling the array with data you should also be counting how many elements you added to it. Generally the result is closer to a typical collection API than an actual array.
I recall people posting in the past that they are dynamically expanded by powers of 2. Hence even knowing the maximum used index will still not reveal the actual underlying size, unless maybe some maths were performed on it. However why one would ever need to know this is beyond me.
Instead of hard coding array indicies when defining the data, dynamically code them. For example...
Set LowGradeConsumableItem[0] = Healing Salve
Set LowGradeConsumableItem[1] = Lesser Clarity Potion​
Becomes...
Set LowGradeConsumableItemCount = 0
Set LowGradeConsumableItem[LowGradeConsumableItemCount] = Healing Salve
Set LowGradeConsumableItemCount = LowGradeConsumableItemCount + 1
Set LowGradeConsumableItem[LowGradeConsumableItemCount] = Lesser Clarity Potion
Set LowGradeConsumableItemCount = LowGradeConsumableItemCount + 1
Not only is this more maintainable since one can modify ordering with trivial effort, but it also leaves the count of elements in LowGradeConsumableItemCount which one can use at a later time, eg to get a random element from the list....
Except they do change in game. JASS arrays (used by GUI) are dynamically expanding storage spaces that can expand to a maximum size of 32,768.
Hello and thank you for responding to my thread, and thanks to everyone else as well!
I took your suggestion about counting but changed it a bit... Since I don''t like the idea of manually counting (to me it kind of
defeats the purpose of a counter) so instead I manually set the highest indices in another variable and used that in my loot drop system like so...
  • Item Table Initialization
    • Events
    • Conditions
    • Actions
      • -------- ------------------------------- --------
      • -------- Array Highest Indices --------
      • -------- ------------------------------- --------
      • Set LGC_Highest_Index = 9
      • Set MGC_Highest_Index = 13
      • Set HGC_Highest_Index = 10
      • Set LGCI_Highest_Index = 2
      • Set MGCI_Highest_Index = 2
      • Set HGCI_Highest_Index = 4
      • Set LGPU_Highest_Index = 3
      • Set MGPU_Highest_Index = 4
      • Set HGPU_Highest_Index = 4
      • Set LGR_Highest_Index = 6
      • Set MGR_Highest_Index = 8
      • Set HGR_Highest_Index = 9
      • Set LGPI_Highest_Index = 8
      • Set MGPI_Highest_Index = 8
      • Set HGPI_Highest_Index = 27
      • Set DWC_Highest_Index = 2
      • Set ToK_Highest_Index = 2
      • Set AM1_Highest_Index = 2
      • Set AM2_Highest_Index = 1
      • -------- -------------------------------------- --------
      • -------- Low Grade Consumables --------
      • -------- -------------------------------------- --------
      • Set LowGradeConsumableItem[0] = Healing Salve
      • Set LowGradeConsumableItem[1] = Lesser Clarity Potion
      • Set LowGradeConsumableItem[2] = Potion of Invisibility
      • Set LowGradeConsumableItem[3] = Vial of Healing
      • Set LowGradeConsumableItem[4] = Vial of Mana
      • Set LowGradeConsumableItem[5] = Vial of Invulnerability
      • Set LowGradeConsumableItem[6] = Potion of Healing
      • Set LowGradeConsumableItem[7] = Potion of Mana
      • Set LowGradeConsumableItem[8] = Replenishment Potion
      • Set LowGradeConsumableItem[9] = Scroll of Speed
      • -------- ------------------------------------- --------
      • -------- Mid Grade Consumables --------
      • -------- ------------------------------------- --------
      • Set MidGradeConsumableItem[0] = Potion of Healing
      • Set MidGradeConsumableItem[1] = Potion of Healing
      • Set MidGradeConsumableItem[2] = Potion of Mana
      • Set MidGradeConsumableItem[3] = Potion of Mana
      • Set MidGradeConsumableItem[4] = |cff1eff00Flask of Exceptional Healing|r
      • Set MidGradeConsumableItem[5] = |cff1eff00Flask of Greater Mana|r
      • Set MidGradeConsumableItem[6] = |cff1eff00Potion of Restoration|r
      • Set MidGradeConsumableItem[7] = |cff1eff00Health Stone|r
      • Set MidGradeConsumableItem[8] = |cff1eff00Mana Stone|r
      • Set MidGradeConsumableItem[9] = Potion of Invulnerability
      • Set MidGradeConsumableItem[11] = |cff1eff00Scroll of Healing|r
      • Set MidGradeConsumableItem[12] = |cff1eff00Scroll of Mana|r
      • Set MidGradeConsumableItem[13] = |cff1eff00Scroll of Protection|r
      • -------- --------------------------------------- --------
      • -------- High Grade Consumables --------
      • -------- --------------------------------------- --------
      • Set HighGradeConsumableItem[0] = |cff0070ddElixir of Spirited Mana|r
      • Set HighGradeConsumableItem[1] = |cff0070ddElixir of Spirited Mana|r
      • Set HighGradeConsumableItem[2] = |cff0070ddElixir of Spirited Mana|r
      • Set HighGradeConsumableItem[3] = |cff0070ddElixir of Zealous Healing|r
      • Set HighGradeConsumableItem[4] = |cff0070ddElixir of Zealous Healing|r
      • Set HighGradeConsumableItem[5] = |cff0070ddElixir of Zealous Healing|r
      • Set HighGradeConsumableItem[6] = |cff0070ddFlask of Powerful Restoration|r
      • Set HighGradeConsumableItem[7] = |cff0070ddFlask of Powerful Restoration|r
      • Set HighGradeConsumableItem[8] = |cffa46331Nesquik|r
      • Set HighGradeConsumableItem[9] = |cff0070ddLovely Phial|r
      • Set HighGradeConsumableItem[10] = |cffa335eeElixir of Mighty Restoration|r
      • -------- --------------------------------------- --------
      • -------- Low Grade Charged Items --------
      • -------- --------------------------------------- --------
      • Set LowGradeChargedItem[0] = Wand of Illusion
      • Set LowGradeChargedItem[1] = Wand of Lightning Shield
      • Set LowGradeChargedItem[2] = Sentry Wards
      • -------- -------------------------------------- --------
      • -------- Mid Grade Charged Items --------
      • -------- -------------------------------------- --------
      • Set MidGradeChargedItem[0] = Fel Token
      • Set MidGradeChargedItem[1] = Red Drake Egg
      • Set MidGradeChargedItem[2] = Stone Token
      • -------- --------------------------------------- --------
      • -------- High Grade Charged Items --------
      • -------- --------------------------------------- --------
      • Set HighGradeChargedItem[0] = |cff1eff00Healing Wards|r
      • Set HighGradeChargedItem[1] = |cff1eff00Ankh of Reincarnation|r
      • Set HighGradeChargedItem[2] = |cff1eff00Ice Shard|r
      • Set HighGradeChargedItem[3] = |cff1eff00Demonic Figurine|r
      • Set HighGradeChargedItem[4] = |cff1eff00Relic of the Wild|r
      • -------- --------------------------------- --------
      • -------- Low Grade Power Ups --------
      • -------- --------------------------------- --------
      • Set LowGradePowerUp[0] = Tome of Agility
      • Set LowGradePowerUp[1] = Tome of Intelligence
      • Set LowGradePowerUp[2] = Tome of Strength
      • Set LowGradePowerUp[3] = Manual of Health
      • -------- --------------------------------- --------
      • -------- Mid Grade Power Ups --------
      • -------- --------------------------------- --------
      • Set MidGradePowerUp[0] = |cff1eff00Tome of Dexterity|r
      • Set MidGradePowerUp[1] = |cff1eff00Tome of Intuition|r
      • Set MidGradePowerUp[2] = |cff1eff00Tome of Intuition|r
      • Set MidGradePowerUp[3] = |cff1eff00Tome of Knowledge|r
      • Set MidGradePowerUp[4] = |cff1eff00Manual of Life|r
      • -------- --------------------------------- --------
      • -------- High Grade Power Ups --------
      • -------- --------------------------------- --------
      • Set HighGradePowerUp[0] = |cff0070ddTome of Brilliance|r
      • Set HighGradePowerUp[1] = |cff0070ddTome of Finesse|r
      • Set HighGradePowerUp[2] = |cff0070ddTome of Vigor|r
      • Set HighGradePowerUp[3] = |cff0070ddTome of Wisdom|r
      • Set HighGradePowerUp[4] = |cff0070ddManual of Vitality|r
      • -------- -------------------------- --------
      • -------- Low Grade Runes --------
      • -------- -------------------------- --------
      • Set LowGradeRune[0] = Rune of Lesser Healing
      • Set LowGradeRune[1] = Rune of Lesser Healing
      • Set LowGradeRune[2] = Rune of Lesser Healing
      • Set LowGradeRune[3] = Rune of Lesser Mana
      • Set LowGradeRune[4] = Rune of Lesser Mana
      • Set LowGradeRune[5] = Rune of Lesser Mana
      • Set LowGradeRune[6] = Rune of Lesser Resurrection
      • -------- -------------------------- --------
      • -------- Mid Grade Runes --------
      • -------- -------------------------- --------
      • Set MidGradeRune[0] = Rune of Healing
      • Set MidGradeRune[1] = Rune of Healing
      • Set MidGradeRune[2] = Rune of Healing
      • Set MidGradeRune[3] = Rune of Mana
      • Set MidGradeRune[4] = Rune of Mana
      • Set MidGradeRune[5] = Rune of Mana
      • Set MidGradeRune[6] = Rune of Armor
      • Set MidGradeRune[7] = Rune of Armor
      • Set MidGradeRune[8] = Rune of Resurrection
      • -------- --------------------------- --------
      • -------- High Grade Runes --------
      • -------- --------------------------- --------
      • Set HighGradeRune[0] = |cff1eff00Rune of Greater Healing|r
      • Set HighGradeRune[1] = |cff1eff00Rune of Greater Healing|r
      • Set HighGradeRune[2] = |cff1eff00Rune of Greater Healing|r
      • Set HighGradeRune[3] = |cff1eff00Rune of Greater Mana|r
      • Set HighGradeRune[4] = |cff1eff00Rune of Greater Mana|r
      • Set HighGradeRune[5] = |cff1eff00Rune of Greater Mana|r
      • Set HighGradeRune[6] = Rune of Armor
      • Set HighGradeRune[7] = Rune of Armor
      • Set HighGradeRune[8] = |cff1eff00Rune of Restoration|r
      • Set HighGradeRune[9] = |cff1eff00Rune of Greater Resurrection|r
      • -------- ------------------------------------------ --------
      • -------- Low Grade Permanent Items --------
      • -------- ------------------------------------------ --------
      • Set LowGradePermanentItem[0] = Claws of Attacking
      • Set LowGradePermanentItem[1] = Ring of Superiority
      • Set LowGradePermanentItem[2] = Gauntlets of Ogre Strength
      • Set LowGradePermanentItem[3] = Mantle of Intelligence
      • Set LowGradePermanentItem[4] = Slippers of Agility
      • Set LowGradePermanentItem[5] = Circlet of Nobility
      • Set LowGradePermanentItem[6] = Ring of Protection
      • Set LowGradePermanentItem[7] = Gloves of Haste
      • Set LowGradePermanentItem[8] = Circlet of Nobility
      • -------- ----------------------------------------- --------
      • -------- Mid Grade Permanent Items --------
      • -------- ----------------------------------------- --------
      • Set MidGradePermanentItem[0] = |cff1eff00Boots of Speed|r
      • Set MidGradePermanentItem[1] = |cff1eff00Claws of Ravaging|r
      • Set MidGradePermanentItem[2] = |cff1eff00Pendant of Energy|r
      • Set MidGradePermanentItem[3] = |cff1eff00Periapt of Vitality|r
      • Set MidGradePermanentItem[4] = |cff1eff00Ring of Defense|r
      • Set MidGradePermanentItem[5] = |cff1eff00Sobi Mask|r
      • Set MidGradePermanentItem[6] = |cff1eff00Belt of Giant Strength|r
      • Set MidGradePermanentItem[7] = |cff1eff00Boots of Quel'Thalas|r
      • Set MidGradePermanentItem[8] = |cff1eff00Robe of the Magi|r
      • -------- ---------------------------------------------------------- --------
      • -------- High Grade Permanent Items & Artifacts --------
      • -------- ---------------------------------------------------------- --------
      • Set HighGradePermanentItem[0] = |cff1eff00Claws of Frenzying|r
      • Set HighGradePermanentItem[1] = |cff1eff00Claws of Frenzying|r
      • Set HighGradePermanentItem[2] = |cff1eff00Claws of Frenzying|r
      • Set HighGradePermanentItem[3] = |cff1eff00Helm of Valor|r
      • Set HighGradePermanentItem[4] = |cff1eff00Helm of Valor|r
      • Set HighGradePermanentItem[5] = |cff1eff00Helm of Valor|r
      • Set HighGradePermanentItem[6] = |cff1eff00Hood of Cunning|r
      • Set HighGradePermanentItem[7] = |cff1eff00Hood of Cunning|r
      • Set HighGradePermanentItem[8] = |cff1eff00Hood of Cunning|r
      • Set HighGradePermanentItem[9] = |cff1eff00Medallion of Courage|r
      • Set HighGradePermanentItem[10] = |cff1eff00Medallion of Courage|r
      • Set HighGradePermanentItem[11] = |cff1eff00Medallion of Courage|r
      • Set HighGradePermanentItem[12] = |cff0070ddClaws of Rampaging|r
      • Set HighGradePermanentItem[13] = |cff0070ddClaws of Rampaging|r
      • Set HighGradePermanentItem[14] = |cff0070ddRing of Wardship|r
      • Set HighGradePermanentItem[15] = |cff0070ddRing of Wardship|r
      • Set HighGradePermanentItem[16] = |cff0070ddKhadgar's Gem of Health|r
      • Set HighGradePermanentItem[17] = |cff0070ddKhadgar's Gem of Health|r
      • Set HighGradePermanentItem[18] = |cff0070ddPendant of Mana|r
      • Set HighGradePermanentItem[19] = |cff0070ddPendant of Mana|r
      • Set HighGradePermanentItem[20] = |cff0070ddCrown of Kings|r
      • Set HighGradePermanentItem[21] = |cff0070ddCrown of Kings|r
      • Set HighGradePermanentItem[22] = |cff0070ddMask of Death|r
      • Set HighGradePermanentItem[23] = |cff0070ddMask of Death|r
      • Set HighGradePermanentItem[24] = |cffa335eeClaws of Annihilation|r
      • Set HighGradePermanentItem[25] = |cffa335eeRing of Preservation|r
      • Set HighGradePermanentItem[26] = |cffa335eeCrown of Emperors|r
      • Set HighGradePermanentItem[27] = |cffa335eeMask of Devastation|r
      • -------- ---------------------------------------------- --------
      • -------- Duskwood Cemetery Boss Item --------
      • -------- ---------------------------------------------- --------
      • Set MorLadimItem[0] = |cffa335eeMor'Ladim's Corrupted Helm|r
      • Set MorLadimItem[1] = |cffa335eeMor'Ladim's Corrupted Shield|r
      • Set MorLadimItem[2] = |cffa335eeMor'Ladim's Corrupted Sword|r
      • -------- --------------------------------------------- --------
      • -------- Throne of Kil'jaeden Boss Item --------
      • -------- --------------------------------------------- --------
      • Set KezzakItem[0] = |cffa335eeAmulet of the Burning Legion|r
      • Set KezzakItem[1] = |cffa335eeClaws of the Burning Raider|r
      • Set KezzakItem[2] = |cffa335eeDiamond of Insight|r
      • -------- ------------------------------------------ --------
      • -------- Abyssal Maw First Boss Item --------
      • -------- ------------------------------------------ --------
      • Set VezaxItem[0] = |cffa335eeBlade of Betrayal|r
      • Set VezaxItem[1] = |cffa335eeHeart of Corruption|r
      • Set VezaxItem[2] = |cffa335eeRelic of Deceit|r
      • -------- ------------------------------------------- --------
      • -------- Abyssal Maw Final Boss Item --------
      • -------- ------------------------------------------- --------
      • Set TestimonyItem[0] = |cffff8c00Kaaxth Shuul, Shawl of a Thousand Deaths|r
      • Set TestimonyItem[1] = |cffff8000An'shel, Ring of the Void|r
  • World Drops
    • Events
      • Unit - A unit Dies
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • ((Owner of (Dying unit)) Equal to Neutral Hostile) and ((Instance Zone <gen> contains (Dying unit)) Equal to False)
    • Actions
      • Set LootChance = (Random integer number between 1 and 100)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Level of (Dying unit)) Greater than or equal to 1) and ((Level of (Dying unit)) Less than or equal to 3)
          • (LootChance Greater than or equal to 1) and (LootChance Less than or equal to 20)
        • Then - Actions
          • Floating Text - Create floating text that reads Bonus Loot! at (Position of (Dying unit)) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
          • Floating Text - Set the velocity of (Last created floating text) to 32.00 towards 90.00 degrees
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Change the lifespan of (Last created floating text) to 2.00 seconds
          • Floating Text - Change the fading age of (Last created floating text) to 0.50 seconds
          • Set LootTypeRoll = (Random integer number between 1 and 4)
          • If (LootTypeRoll Equal to 1) then do (Item - Create LowGradeConsumableItem[(Random integer number between 0 and LGC_Highest_Index)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 2) then do (Item - Create LowGradeChargedItem[(Random integer number between 0 and LGCI_Highest_Index)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 3) then do (Item - Create LowGradePowerUp[(Random integer number between 0 and LGPU_Highest_Index)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 4) then do (Item - Create LowGradePermanentItem[(Random integer number between 0 and LGPI_Highest_Index)] at (Position of (Dying unit))) else do (Do nothing)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Level of (Dying unit)) Greater than or equal to 4) and ((Level of (Dying unit)) Less than or equal to 6)
          • (LootChance Greater than or equal to 1) and (LootChance Less than or equal to 25)
        • Then - Actions
          • Floating Text - Create floating text that reads Bonus Loot! at (Position of (Dying unit)) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
          • Floating Text - Set the velocity of (Last created floating text) to 32.00 towards 90.00 degrees
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Change the lifespan of (Last created floating text) to 2.00 seconds
          • Floating Text - Change the fading age of (Last created floating text) to 0.50 seconds
          • Set LootTypeRoll = (Random integer number between 1 and 4)
          • If (LootTypeRoll Equal to 1) then do (Item - Create MidGradeConsumableItem[(Random integer number between 0 and MGC_Highest_Index)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 2) then do (Item - Create MidGradeChargedItem[(Random integer number between 0 and MGCI_Highest_Index)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 3) then do (Item - Create MidGradePowerUp[(Random integer number between 0 and MGPU_Highest_Index)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 4) then do (Item - Create MidGradePermanentItem[(Random integer number between 0 and MGPI_Highest_Index)] at (Position of (Dying unit))) else do (Do nothing)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Level of (Dying unit)) Greater than or equal to 7) and ((Level of (Dying unit)) Less than or equal to 10)
          • (LootChance Greater than or equal to 1) and (LootChance Less than or equal to 33)
        • Then - Actions
          • Floating Text - Create floating text that reads Bonus Loot! at (Position of (Dying unit)) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
          • Floating Text - Set the velocity of (Last created floating text) to 32.00 towards 90.00 degrees
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Change the lifespan of (Last created floating text) to 2.00 seconds
          • Floating Text - Change the fading age of (Last created floating text) to 0.50 seconds
          • Set LootTypeRoll = (Random integer number between 1 and 4)
          • If (LootTypeRoll Equal to 1) then do (Item - Create HighGradeConsumableItem[(Random integer number between 0 and HGC_Highest_Index)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 2) then do (Item - Create HighGradeChargedItem[(Random integer number between 0 and HGCI_Highest_Index)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 3) then do (Item - Create HighGradePowerUp[(Random integer number between 0 and HGPU_Highest_Index)] at (Position of (Dying unit))) else do (Do nothing)
          • If (LootTypeRoll Equal to 4) then do (Item - Create HighGradePermanentItem[(Random integer number between 0 and HGPI_Highest_Index)] at (Position of (Dying unit))) else do (Do nothing)
        • Else - Actions
This way the loot system is completely dynamic and therefore does not need to be altered if I add any new items to the item table trigger.
I placed a trigger comment to remind me to add 1 to the corresponding index for whichever array in the item table I am editing.
A lot less lines of code than a manually counter too which is always nice!
And after writing all this I didn't even realize @IcemanBo suggested this very thing! I got lost in Dr.SuperGood's gigantic post LOL!
Thanks too all!
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Nope a lot of languages lack them. Technically arrays have no length as they memory lookup instructions. The logical length of the array is however big the space one has allocated for it is. As soon as one assigns a size property to an array that becomes an extra piece of data to store which can add considerable overhead for lots of small arrays. Some modern compilers that know the length of arrays at compile time will optimize out such length property with constants.

Generally only safe languages like C# and Java give arrays an automatic length

True, I do not have immense experience in every language.
I have coded in Java, Javascript, C# and Php though. All of which have it, and those are pretty mainstream so I reckon they are onto something.
 
Level 5
Joined
Jan 19, 2018
Messages
126
Config looks fine. : ) What I personally would prefer is not to pack all "Highest Index" together, but to bind each of them to the corresponding clock where they belong to, but it's ok.
Thanks!
As to your suggestion, I thought it looks neater that way!
Do you think it is better practice to put each Highest Index to its corresponding array
or just a matter of style?
 
Status
Not open for further replies.
Top