what are the limits of arrays?
So, how exactly do I find out how big I can make my arrays?
Do other big arrays have to make my other arrays be smaller?
Does this simply take more GB's of ram in a computer, or are there key bottlenecks to look out for?
I'd like to at least be able to predict if my array will be too big rather than just testing to see if it crashes.
Answer by mezzostatic · Jan 09, 2017 at 11:45 AM
over 2 billion for boolean, it depends how much every element takes in bytes. 2.47 billion is the upper limit of integers in c#.
Answer by tanoshimi · Sep 24, 2016 at 06:26 AM
Arrays can be huge. They're the structure that Unity uses to store the vertices and triangles of every mesh in the scene, for example. What matters, performance-wise, is how you access the members of that array. You don't want to be iterating over all the members of a million-element array in a for loop or resorting that array every frame, for example.
Whatever bottlenecks you may have in your game, using arrays to store data is never going to be one of them.
Right. I'm just assu$$anonymous$$g a huge pile of data where you might simply look at one tiny piece of it at a time.
Say for example, you recorded every object's movement in Vector3 and Quaternion for every frame of the game. Imagine there are hundreds, maybe thousands of objects all being recorded.
At 60fps, how many days until your game crashes? I would not know.
Floating point problems are really easy to find. Just launch your physics objects out at really long distances and see all the amazing rounding error glitches. But I want to know the real limits of arrays. You say huge, but how huge? How many million?
Also, will slower computers crash sooner? These are all very important things to know.
Crashing is nothing to do with your framerate or having a "slower" computer - it's caused by memory allocation.
An array holds a set of references to the objects it contains. Each of those references is 4 bytes (on a 32bit system) or 8 bytes (on 64bit). So, multiply that by the number of elements to get an idea of memory requirements. A modern machine can comfortably hold several billion elements in an array.
so, it's based on the number of bytes per element? So, then how many elements depends on the data type like Int, float, Vector3, or if it is a link to an object/component. So, when you add it all together, it should be less than how much RA$$anonymous$$ your computer has?
Also, what I meant by FPS is when recording game object's motion. So, at 60FPS, in 2 days, your array's size would become 10,368,000. So, 10,368,000 Vector3's and 10,368,000 Quaternions times how ever many objects are in the game. Let's say 1000. So that comes to a total of 20,736,000,000 elements. That's only if someone decided to leave the game running for 2 days, and that there was no limit to how long you could record for. So, 20 billion.
But anyway. I know not a very realistic example, but it would be nice to sort of have an idea on how to budget these.
Answer by Honour-Demon · Jun 05, 2019 at 08:36 PM
Hmmm 2016 Q. But here we Go.
2d array Example: (Variable memory allocation) + (array reference information).
(x*y* variable size) + (x*y* 4 x bytes) = 25 bytes + 100 bytes = 125 bytes if it was 5x5 byte array.
{I'm just using basic thought here. I didn't look up the values}. The same logic counts for any kind of dimensional array that uses a fixed size variable, like say a bool or Vector3 or int or etc.
So in short. How much Memory you got to work with. {Edit: Forgot the <-- actual Answer}.
Good Luck.
(Edit: Simplified Stuff)
Your answer
Follow this Question
Related Questions
Why does this loop throw an error if int questComplete rises above 1? 0 Answers
Managing In-Game Variables of Different Data Types 1 Answer
Defining a number of gameobjects from another gameobject 0 Answers
animation array trying to play all at once 0 Answers
Cannot Set Array Size in Inspector 2 Answers