Optimizing C Structure Layout with alignas and offsetof
C structs include invisible padding for alignment. Learn how alignas and offsetof let you measure and control layout to avoid memory waste and false sharing.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
C structs include invisible padding for alignment. Learn how alignas and offsetof let you measure and control layout to avoid memory waste and false sharing.
A C struct holding 13 bytes of data can quietly occupy 24. Here is how to measure padding with sizeof and offsetof, and reclaim the waste by reordering members.