limited size of array
-
>@tack!<
- Adept
- Posts: 338
- Joined: Sat Apr 17, 2010 4:51 pm
- Personal rank: lol?
limited size of array
hey im trying to save lots of vectors ( around 600 or 1200 or more if possible ) in variables as an array. only it seems that an array of vectors can have only 21. do i have to make 30 different vars to have around 600 vectors stored or is there some other way?
-
Shadow
- Masterful
- Posts: 745
- Joined: Tue Jan 29, 2008 12:00 am
- Personal rank: Mad Carpenter
- Location: Germany
Re: limited size of array
Never heard of THAT limitation, internally a mesh saves hundreds of vectors as vertices so this MUST be possible. Also internally vector components get converted to int for saving memory. Have you tried out a higher array length than 21 already? Why do you want to save so many vectors? I'm curious.
-
>@tack!<
- Adept
- Posts: 338
- Joined: Sat Apr 17, 2010 4:51 pm
- Personal rank: lol?
Re: limited size of array
the editor tells me at values higher than 21 that im above 255 bytes or somtin. but it only says it when i have a line that sets the variable. if i only declare it theres no error. and i actually store locations every .5 sec ( i guess ) so i maybe can make some sort of ghost for BT that will go trough those locations if you want to so you can compete with yourself ^^. ( i had this idea this morning and im not that good a scripter so if i do it totally the wrong way im sorry :p)
-
Feralidragon
- Godlike
- Posts: 5503
- Joined: Wed Feb 27, 2008 6:24 pm
- Personal rank: Work In Progress
- Location: Liandri
Re: limited size of array
That problem is easy to fix, but first an explanation why it happens:
- In UT, when you're accessing "directly" an array which has more than 255 bytes of info, it just blows up. You're not allowed to do this, it's a limitation from UT.
Well, considering that a float in UT has 32bits, or in other words, 4 bytes of data, the max array size should be 63 (0 to 62), since: 255/4 = 63.75 ==> 63.
A vector in UT is actually a struct with 3 floats of data: X, Y and Z. Which means that in each index you have 3 floats, or 12 bytes of data (3 x 4 bytes = 12 bytes).
Therefore, the max array size you can have from vectors is 21 (0 to 20): 255/12 = 21.25 ==> 21.
However, this limitation is felt, again, only when "directly accessing an array from another class or instance", there's no limitation I know of relative an array size by itself.
As long you work with the array within the same class and same instance ONLY, this limitation never occurs.
So basically, this happens because you're accessing the array which is in class A from class B, you are doing something like this:
That will lead to that error, because you're accessing an array bigger than 255 bytes DIRECTLY. So you can get around this by accessing the array INDIRECTLY in the context of its own instance/class, by defining "getters" in the class with the array (in Oriented Object Programming you have different kinds of functions: constructors, setters, getters, methods, "functions", etc).
A "getter" is a function which the only purpose is to "get" a specific value, so the way to do this here is like this:
Something like that should work, because you never access the array directly, since you use "getters" to return the values you actually need from it.
- In UT, when you're accessing "directly" an array which has more than 255 bytes of info, it just blows up. You're not allowed to do this, it's a limitation from UT.
Well, considering that a float in UT has 32bits, or in other words, 4 bytes of data, the max array size should be 63 (0 to 62), since: 255/4 = 63.75 ==> 63.
A vector in UT is actually a struct with 3 floats of data: X, Y and Z. Which means that in each index you have 3 floats, or 12 bytes of data (3 x 4 bytes = 12 bytes).
Therefore, the max array size you can have from vectors is 21 (0 to 20): 255/12 = 21.25 ==> 21.
However, this limitation is felt, again, only when "directly accessing an array from another class or instance", there's no limitation I know of relative an array size by itself.
As long you work with the array within the same class and same instance ONLY, this limitation never occurs.
So basically, this happens because you're accessing the array which is in class A from class B, you are doing something like this:
Code: Select all
//One class - Class AAAA
class AAAA
{
var vector MyArray[5000];
}
//Another class - Class BBBB
class BBBB
{
var AAAA a;
var vector something;
function Whatever()
{
local int i;
for (i = 0; i < ArrayCount(a.MyArray); i++)
something = a.MyArray[i];
}
}A "getter" is a function which the only purpose is to "get" a specific value, so the way to do this here is like this:
Code: Select all
//One class - Class AAAA
class AAAA
{
var vector MyArray[5000];
function vector getMyArrayVector(int index)
{
return MyArray[index];
}
function int getMyArrayLength()
{
return ArrayCount(MyArray);
}
}
//Another class - Class BBBB
class BBBB
{
var AAAA a;
var vector something;
function Whatever()
{
local int i;
for (i = 0; i < a.getMyArrayLength(); i++)
something = a.getMyArrayVector(i);
}
}-
>@tack!<
- Adept
- Posts: 338
- Joined: Sat Apr 17, 2010 4:51 pm
- Personal rank: lol?
Re: limited size of array
tyvm feralidragon, it was very supsicious having max zone limit 63 and vectors having 3 floats and having a limit of 21 when doing it directly. ill try this soon, im currently working on some maps for BT first.

