macOSLinuxWindowswasm
#import "Soa";
Fixed-size arrays of structs stored as one array per member.
Procedures#
(array: *$S/
Soa, body:
Code, flags: For_Flags)
Lets a Soa be used in a for loop over its N elements; it is a copy of the element and it_index its index.
Pair :: struct { a: int; b: int; }
values: Soa(Pair, 2);
for *pair, index: values pair.a = index + 10;
total := 0;
for pair: values total += pair.a;
assert(total == 21);
↗
()
A small demonstration of writing and reading an element. It exists as a smoke test and is not part of the API.
Types#
:: struct
Soa(T, N): N values of the struct T, stored as one array per member ("structure of arrays") instead of one array of structs.
Particle :: struct { x: float; y: float; }
particles: Soa(Particle, 3);
particles[1] = .{ 2, 5 };
assert(particles[1].y == 5 && particles[0].x == 0);
particles.x[2] = 9; // a member is an ordinary array
assert(particles[2].x == 9);
↗