• 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.

Technical Question regarding memory arrays

Status
Not open for further replies.
Level 13
Joined
Mar 24, 2010
Messages
950
So was just wondering this.. you know in the place you create variables.
Well when you make it an array theres an option to declare the number of array you'll be using.

I'm wondering is there any advantage to doing this. I notice especially with integers it will just make them without setting a exact number, you can leave it [1] and it will go on forever if you just set it later via triggers.

But i also notice with certain arrays it will glitch or not work unless the array length number is set in there, i think with unit groups maybe this is the case, cant remember what variable type it was that did that.

This is what i assume to be the case. Pre-setting the array length value in there creates the memory space for it at initialization aka statically assigning memory for the array length you specify.
So in other words if you have an int array your using and you want 12 in the array if you set that number value in there for the array length you want of 12, that memory space in the map is pre reserved for those 12 array integers or whatever variable type your using. If your lazy and just leave it as default at 1 it will work dynamically and create memory space for it during the game when its first used or referenced.

am i right in my assumptions? if not let me know.
 
Level 19
Joined
Feb 25, 2009
Messages
2,004
Not exactly what you've stated.

Any variable array has a size of maximum number 8191, which is it's limit, and it won't go any further.

The size in the variable editor doesn't really matter, because the script will anyway initialiaze all of it's array size (again, up to 8191) so in other other words - when making an array variable just tick the "Array" checker and thats all.
 
Level 10
Joined
Jun 26, 2005
Messages
236
That feature just initializes the variables, ie., assigns default (or chosen) values to the amount of indicies specified, so they are ready for instant use. So, for example, if you declared that there was, let's say, "1337" amount of indicies, it will generate this code in the script:

JASS:
local integer i = 0
loop
    exitwhen (i > 1337)
    set someMassiveArray[i] = 0
    set i = i + 1
endloop

That's all it does... you can still use any other index freely.
 
Level 13
Joined
Mar 24, 2010
Messages
950
Not exactly what you've stated.

Any variable array has a size of maximum number 8191, which is it's limit, and it won't go any further.

The size in the variable editor doesn't really matter, because the script will anyway initialiaze all of it's array size (again, up to 8191) so in other other words - when making an array variable just tick the "Array" checker and thats all.

So declaring the array size in there does nothing eh? it always assumes the full 8191 length of array will be used?

in that case i have another question.
Is it more efficient to use like 5 separate standard integers or 1 integer with an array of 5?

I think if you increase it, it's limit will remain 8191, but it takes up 1KB of space in the map.
That's what I discovered when I saved a map with array variables that I set up to 18.

so your saying it takes 1KB of space in a map if the array values set at 18? or its still 1KB at 8191 also

That feature just initializes the variables, ie., assigns default (or chosen) values to the amount of indicies specified, so they are ready for instant use. So, for example, if you declared that there was, let's say, "1337" amount of indicies, it will generate this code in the script:

JASS:
local integer i = 0
loop
    exitwhen (i > 1337)
    set someMassiveArray[i] = 0
    set i = i + 1
endloop

That's all it does... you can still use any other index freely.

you are talking about the array value right not the integer value itself?

like Temp_int[5] your talking about the array size 5 number not the Temp_int number correct?
 
>> Is it more efficient to use like 5 separate standard integers or 1 integer with an array of 5?

The decision is yours to make. Most of the time, you need speed, so you should use scalar variables (non-arrays).

In programming languages I am used to, elements of an array are nonexistent until the highest value has been set. If the first thing you do to an array is:

set x[100] = "hello world"

You have created a list of size 101, with 100 values of default content (for strings, it's ""). If the first thing you do to an array is:

set x[0] = "goodbye"

You have created an array of size 1. JASS may work differently, and I've read arrays are created by powers of 2. So every new power of two, a new section of arrays have been filled. If this is true,

set x[0] = 1 sets x[0] to 1 and x[1] is defaulted to 0.
set x[2] = 1 sets x[0..1] to default (0), x[2] to 1 and x[3..4] to default.

This may not be accurate, so don't quote me on this.
 
Level 10
Joined
Jun 26, 2005
Messages
236
Bond009 said:
you are talking about the array value right not the integer value itself?

like Temp_int[5] your talking about the array size 5 number not the Temp_int number correct?

I'm saying that the feature that "declares the array size" is not really declaring the size, but really initializing that amount of variables.

So like in my example above, if you had a Boolean Array of size 5, it will put code in the script that sets someBoolean[0, 1, ... 5] to false.
 
Level 13
Joined
Mar 24, 2010
Messages
950
@Bone
ok eye sea


@Bribe
So then it doesn't really matter if i make like 4 separate scalar variables of for example player-groups or a player group array with 4 as long as im using [0-3] otherwise im wasting 0 so then its truly 5..

i think your right arrays probably work on bit system as does everything. so if your using anything beyond [0-1] your moving on to using 2 bits and so on eh.
 
Yeah, that's the main thing. A lot of GUI systems use arrays strangely - they count the number of running instances but keep the array index itself unchanged until the instances shrinks down to zero.

That means if: an instance is destroyed 1 second after it is created, but an instance is created every 0.5 seconds, the array position will never shrink down. Bad design.

The stack and pop method, which proper arrays use, works much more efficiently. Thankfully, the structs Vexorian made for vJass use stacking instead of that crappy GUI way.
 
Level 19
Joined
Feb 25, 2009
Messages
2,004
It's not really like that..

Most system in GUI using array for instaces, change the main integer array size by 1 everytime the trigger for it is used, and shrink it everytime all instances are done.

Better GUI systems recycle the instances, meaning - when an instance ends and there's anohter one after it, that instance will take it places and free it's array place in the chain.
 
Status
Not open for further replies.
Top