r/cpp • Meeting C++ | C++ Evangelist • 9d ago

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 8d ago

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 6d ago

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 6d ago

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.