2 ms·
Struct of arrays have the potential to be much more memory efficient if the original struct had padding. struct Foo { int64_t i; int8_t c; // 7 bytes
by compiler-guy 1y ago
Struct of arrays have the potential to be much more memory efficient if the original struct had padding.
struct Foo {
int64_t i;
int8_t c;
// 7 bytes of padding for alignment.
};
A Foo array will have seven bytes of wasted space per element. That can add up, and can even blow away what would be nice caching effects if looking at both elements.
Access patterns do matter a lot to this, but it isn't as easy as describing one. Always profile.
[Edit, I wish hn supported markdown.]
- WalterGR 1y agoLines that start with 2 spaces are monospaced. https://news.ycombinator.com/formatdoc https://news.ycombinator.com/formatdoc