- Home /
Builtin Clarifications
I'm using builtin arrays for a lot of ai stuff like prioritizing actions and keeping track of known objects, etc.
When I first started using Unity I was told that while the builtin arrays are very fast they lack the functionality of other array types.
Right now I'm pretty exclusively using builtin arrays, even for things like sorting, paired sorting, and binary searches, etc.
The language i'm using for these functions is stuff like System.Array.Sort(builtin), or System.Array.BinarySearch(builtin, object)
What I wanted to know is whether I'm taking advantage of the speed of the builtin arrays, or whether what I'm really doing is instantiating new mono arrays, performing the functions, and then converting the result back to the builtin array (when the array is altered by said function, rather than just having it return an int or whatever), and if that's the case whether it's lighter on the performance cost to iterate through the builtin arrays myself with for loops and such.
I'm not much of a programmer, just really been tooling around unity in my spare time, so I was hoping that someone here might help clarify the issue.
Thanks,
Dravel
Answer by yoyo · Aug 14, 2014 at 05:59 AM
A Mono array and a built-in array are the same thing -- an instance of System.Array. There is only a difference in javascript, which has its own arrays -- these are less efficient. The main drawback of a built-in array is that once allocated it cannot be resized. You can allocate a new, larger (or smaller) array and copy the original array, but you cannot resize the original array directly. Searching and sorting should be efficient, though if you need to keep re-sorting an array you might be better off with data structures like Dictionary or SortedList, which are only available from C#, not javascript.
More information can be found in the Array documentation.
Your answer
![](https://koobas.hobune.stream/wayback/20220613100509im_/https://answers.unity.com/themes/thub/images/avi.jpg)