3 ms·
I tend to only use packed structures when I need to match a binary format or know I'll create huge arrays of structures. For the rest I blindly trust the compi
by jeremiep 13y ago
I tend to only use packed structures when I need to match a binary format or know I'll create huge arrays of structures.
For the rest I blindly trust the compiler to choose optimal boundaries and alignments.
- dfox 13y agoProblem with that approach is that compiler cannot do any optimalizations of struct field layout as it's completely specified by platform ABI and order in which are fields declared.
- soup10 13y agoThe compiler can't rearrange your structure data for optimal packing, because it doesn't know if you rely on the ordering of it. I agree that structure packing is mostly unnecessary optimization except for a few high performance scenarios where cache miss frequency has a huge impact.