June 23, 2025Jun 23 Data-oriented design is all about reorganizing data for better performance, and Andrew Kelleyâs talk on the topicâespecially his use of Zigâs MultiArrayListâoffered a compelling real-world example. Inspired by that, this post explores how we can achieve a similar âstruct-of-arraysâ approach in C++26 using reflection to build a SoaVector<T> that separates member storage for improved memory locality and performance. Implementing a Struct of Arrays by Barry Revzin From the article: Recently, I watched Andrew Kelleyâs talk on Practical Data Oriented Design. It goes into some of the architectural changes heâs been making to the Zig compiler, with pretty significant performance benefit. Would definitely recommend checking out the talk, even if youâre like me and have never written any Zig. About halfway through the talk, he shows a way to improve his memory usage by avoiding wasting memory. By turning this structure: const Monster = struct { anim : *Animation, kind : Kind, const Kind = enum { snake, bat, wolf, dingo, human }; }; var monsters : ArrayList(Monster) = .{}; into this one: var monsters : MultiArrayList(Monster) = .{}; ArrayList(Monster) is what we could call std::vector<Monster>, and MultiArrayList(Monster) now stores the anims and kinds in two separate arrays, instead of one. That is, a struct of arrays instead of an array of structs. But itâs a tiny code change. View the full article
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.