An array of structs stores struct values together in the array’s contiguous memory block. Unlike an array of class references, its elements’ data is stored together, making its placement easier to plan for CPU cache access. section 2.5
In data-oriented design, separate arrays are usually preferred to maximize data locality. Group fields in an array of structs when they are always used together and no other logic needs them separately. section 2.5
Coin pickup animations
A coin flying from the pickup location to the UI needs a current position, target position, and velocity. Keeping those fields together in a CoinStruct array suits a system that processes them together. A string field would weaken locality because each string’s data is allocated separately. section 2.5
Listing 2.20 Example of struct and class arrays
public struct CoinStruct
{
public Vector2 CurrentPosition;
public Vector2 TargetPosition;
public float Velocity;
}
public class CoinClass
{
public Vector2 CurrentPosition;
public Vector2 TargetPosition;
public float Velocity;
}
CoinStruct CoinStructArray = new CoinStruct[4];
CoinClass CoinClassArray = new CoinClass[4];The C# listing defines matching coin data as a struct and class, then declares an array of each for comparison. section 2.5

