Benchmarks comparing run times with hardcoded SoA layouts revealed the following issue:
#include <vector>
struct SoA_Points { std::vector<float> x, y, z; };
struct S_ref { float &x, &y, &z; };
struct wrapper {
SoA_Points soa_points;
S_ref operator[]( int i ) {
return { soa_points.x[i], soa_points.y[i], soa_points.z[i] };
}
};
int main() {
int N = 100;
wrapper w {{ std::vector<float>(N), std::vector<float>(N), std::vector<float>(N) }};
w[42].x = 3; // Accesses all data members of soa_points, although only x is needed
return 0;
}
I am trying to find a solution for this problem.