Efficient Data Structures
Context
- Create data structures for controling the data layout (AoS vs SoA)
- These data structures should hide the underlying data layout.
- We want to change the underlying data layout without affecting the code using it.
Approach using a skeleton class (Stephen)
/*
... omitted code ...
... omitted code ...
... omitted code ...
*/
template <template <typename> typename F>
struct S {
using tuple_t = std::tuple<int, int, double, int>;
F<int> x, y;
F<double> activation;
F<int> identifier;
};
int main() {
array_wrapper<aos, S>::owner my_array_owner(4); // aos can be changed to soa
array_wrapper<aos, S>::handle my_array(my_array_owner); // aos can be changed to soa
for (int i = 0; i < 4; i++) {
auto my_element = my_array[i];
my_element.x = i - 10;
my_element.y = i + 50;
my_element.activation = std::sin(static_cast<double>(i));
my_element.identifier = i;
}
return 0;
}
Advantages:
- We can provide a nice interface, like the ".x" syntax.
- Allows seemless switch between AoS and SoA.
Disdvantages:
- The skeleton class has to be implemented for every class that we want to support.
David's variation of this approach
- We want to support a "placement new", i.e. allocate within an existing buffer.
- Needs "counting" for structured bindings (Question to Giulio: How did you do it?)