C#C
C#4mo ago
peppy

Use of inline arrays to model arrays of structs

For a native type with the following shape:
public struct CHRDATA {
    public uint hp;
    public uint mp; // ... hundreds more fields
}
public struct SAVEDATA {
    public CHRDATA chr1;
    public CHRDATA chr2;   
    public CHRDATA chr3; // ... tens more entries
}

it occurred to me I could represent the sequential CHRDATAs with an InlineArray as such:
[InlineArray(80)]
public struct CHRDATA_ARRAY {
    private CHRDATA _c;
}
public struct SAVEDATA {
    public CHRDATA_ARRAY chrs;
}

which raises a few questions, since I'm unfamiliar with the feature:
1) is this legal? can you make InlineArrays of blittable structs, or should usage of InlineArray be restricted to primitives? (i.e. int, float)
2) does chrs[62].hp = 300; in the above case operate on a copy or actually mutate the relevant part of SAVEDATA?
Was this page helpful?