user49471: I am working on a project where i need to store as fast I can following :
1 - Acceleration on X
2 - Acceleration on Y
3 - Acceleration on Z
4 - timestamp
5 - A value from some other sensor
Because I need to get these as fast as I can I am thinking to not do any calculation while acquire values and just store them for 30 -60 seconds and then when the "test" is complete to compute calculations.
My question is if will be better to create 5 arrays and put these values there or create a matrix and store values there.
I need these values to be stored like they are "connected"
e.g. on reading 1 i get 5 values and put them on array[0] , then on reading 1 and so on
Also an important thing to mention, this will run on a esp32.
Thank you

user31105: I fully agree with Edgar Bonet.
My opinion is keeping a 'matrix' is better, or actually one array (of structs), where each array elements stores all information for one measurement (which is stored inside one struct). This has some benefits:

Data of one measurement is consecutive in memory, so you can easily transfer it (to some external memory or sending it). It's exact one struct (and you can use sizeof(struct_item) to know how many bytes you have to transfer.
It's good practice in general to keep information together, creating 5 always-equal length arrays seems strange.
If for some reason you want to make a single array dynamic or change it to a ring buffer for example, you can easily add/remove items (instead of dynamically changing 5 arrays).
Locality of change (see comments of Kwasmich/DuncanC)

There is also one benefit about having separate arrays (where each array stores one type of information, like an acceleration or timestamp: when you have a function (especially in another class) that only needs one of them, you can specifically send that array (or pointer/reference), so the other information is hidden from that function.

49471: <p>I am working on a project where i need to store as fast I can following :</p>

<p>1 - Acceleration on X</p>

<p>2 - Acceleration on Y</p>

<p>3 - Acceleration on Z</p>

<p>4 - timestamp</p>

<p>5 - A value from some other sensor</p>

<p>Because I need to get these as fast as I can I am thinking to not do any calculation while acquire values and just store them for 30 -60 seconds and then when the "test" is complete to compute calculations.
My question is if will be better to create 5 arrays and put these values there or create a matrix and store values there.
I need these values to be stored like they are "connected"
e.g. on reading 1 i get 5 values and put them on array[0] , then on reading 1 and so on
Also an important thing to mention, this will run on a esp32.</p>

<p>Thank you</p>
 31105: <p>I fully agree with Edgar Bonet.</p>

<p>My opinion is keeping a 'matrix' is better, or actually one array (of structs), where each array elements stores all information for one measurement (which is stored inside one struct). This has some benefits:</p>

<ul>
<li><p>Data of one measurement is consecutive in memory, so you can easily transfer it (to some external memory or sending it). It's exact one struct (and you can use <code>sizeof(struct_item)</code> to know how many bytes you have to transfer.</p></li>
<li><p>It's good practice in general to keep information together, creating 5 always-equal length arrays seems strange.</p></li>
<li>If for some reason you want to make a single array dynamic or change it to a ring buffer for example, you can easily add/remove items (instead of dynamically changing 5 arrays).</li>
<li>Locality of change (see comments of Kwasmich/DuncanC)</li>
</ul>

<p>There is also one benefit about having separate arrays (where each array stores one type of information, like an acceleration or timestamp: when you have a function (especially in another class) that only needs one of them, you can specifically send that array (or pointer/reference), so the other information is hidden from that function.</p>
