r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • Sep 24 '26
About alignment, struct layout and the cache...
https://meetingcpp.com/blog/items/About-alignment--struct-layout-and-the-cache---.html
36
Upvotes
View all comments
Show parent comment
3
u/imMute Sep 27 '26
You could make an attribute that you apply on a class definition to make the reflection machinery reorder the members to reduce padding to as little as possible.
Reflection and serialization are a match made in heaven.
You could do stuff like #1 but for adjusting for cachline size to reduce false sharing.
You could pack a bunch of
bools into a single word to reduce space (at the cost of losing the ability to take the address of the bools).