Master the fundamental concepts of cache optimization through this focused micro-challenge.
Array of Structures (AoS) stores all fields per object together. Structure of Arrays (SoA) stores each field in its own contiguous array. Game engines and SIMD kernels prefer SoA when loops touch one field across many entities. AoS wins when you always load whole records together.
Updating positions for 100k particles: SoA lets you vectorize x[], y[], z[] without gathering scattered fields. Printing full records: AoS avoids three pointer chases.
cLoading…
Keep the relevant documentation open while you implement. When your output disagrees with the reference, trace one failing case by hand before changing random lines.
You will benchmark AoS vs SoA for a field-heavy update loop and report speedup. This exercise asks you to tie the winner to which fields the inner loop reads.
Benchmark Structure of Arrays vs Array of Structures.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github