- Home /
how are arrays stored in memory in the iOs Player
I am developing an iOs project which needs to store a lot of optimised level data.
Because I am developing for iOS I want the smallest memory foot print possible.
The data is a large number (tens of thousands) of simple structures e,g,
'MyVector' is a class with 3 int members x,y, and z
MyVector3[] a10000Vectors = new MyVector3[10000];
Does anyone know how an array of this kind would be stored in memory?
Is there a single block of memory with 30000 closely packed ints or is it this plus another array of 10,000 pointers into 10,000 addresses in this block or is it a list of 10,000 pointers and 10,000 separately allocated tiny blocks of memory or something else?
Also does it make a difference if these are structs or classes? Do structs and classes have the same distinction in Unity that they do under .Net/Mono. Are structs values and classes reference values?
Is it smaller to have 3 separate arrays of int one for each components of the vectors?
Thanks in advance for any help.
Answer by Eric5h5 · Apr 05, 2012 at 04:50 PM
Unity uses Mono, so anything that applies to Mono applies to Unity. A Vector3 is 3 floats, so one Vector3 uses 12 bytes. There are no ints involved (although ints and floats both use 4 bytes.) Making 3 arrays of floats vs. 1 array of Vector3 makes no difference as far as memory goes; you are using the same amount of data both ways.
Thanks for this.
Am I right in assu$$anonymous$$g that if you use classes ins$$anonymous$$d of structs there would be 10,000 separately allocations on the heap plus one for the list/array of pointers to those allocations?
Correct. In the case you specify, there should be 360,000 bytes allocated (plus some overhead, of course).
Your answer
![](https://koobas.hobune.stream/wayback/20220613065942im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Enable MeshRenderer from all objects in array 1 Answer
iOS crash on load: Terminated due to memory issue (Unity5.2.1p3) 0 Answers
How to pass and return an array b/w c# script and c++ plugin 0 Answers
IOS EXC_BAD_ACCESS code=2 ? 1 Answer
IOS Terminated due to memory issue because of a 2D animation with 60 frames in it 1 Answer