4 ms·
I remember Zig is able to convert arrays of struct to struct to arrays in compile time [1], which effectively sidesteps all the need for the user to worry about
by giovannibonetti 3y ago
I remember Zig is able to convert arrays of struct to struct to arrays in compile time [1], which effectively sidesteps all the need for the user to worry about array indices and having them in the right range.
https://zig.news/kristoff/struct-of-arrays-soa-in-zig-easy-in-userland-40m0 https://zig.news/kristoff/struct-of-arrays-soa-in-zig-easy-i...
- aw1621107 3y ago> which effectively sidesteps all the need for the user to worry about array indices and having them in the right range. How does converting AoS to SoA eliminate the need to worry about array indices? If you have an array of structs with N entities and convert that to a struct of arrays each array would also have N entities, so out-of-bounds accesses in one would be equally out-of-bounds in the other.
- giovannibonetti 3y agoYou can use iterators and skip over indices completely.
- aw1621107 3y agoWouldn't that apply to both AoS and SoA, though?
- giovannibonetti 3y agoYes, but in languages that don't have this feature, to make use of the SoA optimization you would need to manually control the indices.