Data Structures & Algorithms · Interview question

What's the difference between array-of-structs and struct-of-arrays, and when does each win?

A strong answer

Array-of-structs (AoS) stores each record's fields together: struct Sample { uint32_t t; int16_t x,y,z; } log[256];, sample i's fields are adjacent. Struct-of-arrays (SoA) stores each field in its own parallel array: separate t[256], x[256], y[256], z[256]. AoS wins when you process whole records at once (you touch log[i].x/.y/.z together, and they're contiguous). SoA wins when you sweep a single field across all records, averaging every x, or running a DSP filter on one axis, because that field is then contiguous, giving sequential cache-friendly access and enabling SIMD/vectorization. SoA can also pack tighter by avoiding per-element padding between unlike-sized fields. The choice is driven by your dominant access pattern; for signal processing that streams one channel, SoA is often markedly faster.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Arrays & Memory Layout

Contiguous storage is why arrays give O(1) indexing and why row-major traversal is cache-friendly, plus array-of-structs vs struct-of-arrays for embedded data.

More Arrays & Memory Layout questions

Browse all 472 interview questions
What's the difference between array-of-structs and struct-of-arrays, and when does each win? | EmbeddedPrep.io