Skip to main content
3 of 3
added 59 characters in body
Michel Keijzers
  • 13k
  • 7
  • 42
  • 59

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.

Michel Keijzers
  • 13k
  • 7
  • 42
  • 59