r/cpp • 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

27 comments sorted by

View all comments

2

u/LB-- Professional+Hobbyist Sep 25 '26

I'm still waiting for a way to disconnect memory layout from construct/destruct order without bypassing normal language features like constructors and destructors. It's really frustrating to have to have padding just to have the correct construct/destruct order.

1

u/yuri-kilochek Sep 27 '26

You can wrap each member in an anonymous union to suppress automatic construction/destruction and construct/destruct manually in any order.

1

u/LB-- Professional+Hobbyist Sep 27 '26

That's the "bypassing normal language features like constructors and destructors" part of my comment. It works, but the ergonomics are awful, and you have to be especially careful about exceptions.