Structure of arrays and array of structures

What are the possibilities of getting this added to Ada/GNAT as a new representation clause aspect? This would tell the compiler to structure arrays of records differently depending on what is set.

Second that. If possible, that would be a great addition as it would help enable better performance with little change to the source code.

1 Like

I’m sorry; I don’t understand what you mean; can you explain?

Wikipedia explains it. It’s for organising memory for SIMD access and Ada could easily do it with an aspect without even changing the language.

The required syntax changes would be minor for type declarations and variable declarations, at least if the extension is introduced as a new aspect, perhaps called “Column_Order” (from the term column-oriented databases).

However, I think there would be many semantic questions that would have to be answered in the Ada RM and many restrictions that would have to be checked or worked around in many parts of an Ada compiler, including:

  • any representation clauses on the element type (a record type, one assumes) would have to be ignored or forbidden
  • it would not be possible to use an element of the array as a pass-by-reference parameter, nor to take the 'Access or 'Address of an element
  • an array-of records object forced to have the record-of-arrays representation would be incompatible with a formal parameter defined to be of an otherwise compatible type but with the normal representation (or, in the unlikely case of pass-by-value, would require a very cumbersome conversion)
  • the syntax and semantics of formal generic parameters would also have to be extended for array types with the record-of-arrays representation to be used as actual generic array type parameters, and of course the use of a record-of-arrays representation in the formal parameters would make the generic unit incompatible with ordinary array-of-records representations.

Also, since the goal is performance optimization, it is likely that there would soon arise demand for controlling the representation of the per-component arrays of the record-of-arrays representation, for example to require the ability to Pack some of them, and that could not be done with just one new aspect. So, as is often the case, a language addition that appears simple turns out to be more complex.

Given all the restrictions that would apply to the usage of an array-of-records represented as a record-of-arrays, it seems to me that it would be just as easy to code it as a record-of-arrays (or even just a set of independent arrays) using existing Ada features. Hopefully the data and operations will anyway be abstracted into a package with an interface that does not reveal which representation is used within the package.