Implementation of FInstancedStruct with SBO (Small Buffer Optimization) with default buffer size of 24 bytes.
Particularly useful when the expected types rarely exceed the buffer size, such as optional payload data.
Serialization compatible (non-commutative) with FInstancedStruct.
FVariadicStruct has some key differences from FInstancedStruct that should be taken into account:
- Requires 32 bytes instead of 16 and 16-byte alignment instead of 8.
- Requires extra steps to access the data including 1 branching and 1 indirection if the type doesn't match.
- Move constructor and move assignment operator require a copy constructor for types that fit into the buffer.
- Similar to
FInstancedStructContainer, not exposed to the Editor and BP as it doesn't make much sense.
FInstancedStructContainermight still be more preferable for contiguous heterogeneous data.
You should pay attention to how you assign a new structure value into the existing FVariadicStruct:
- Construct a new structure from type and copy its value using type erasure:
Variadic = FVariadicStruct::Make(MyVector); - Copy construct a new structure using native constructor:
Variadic.InitializeAs<FVector>(MyVector); - Copy a structure into the existing value without reconstructing:
Variadic.GetMutableValue<FVector>() = MyVector;
The results are very approximate due to the superficiality of the tests performed under Development configuration.
| x | type ctor | script ctor | load (est/seq/rnd) | store (est/seq/rnd) | note |
|---|---|---|---|---|---|
| SBO | 1.82 | 1.79 | 1.47/1.06/3.21 | 1.24/1.01/2.25 | The difference is greatest with a large number of cache misses and least with sequential access. |
| HEAP | 1.02 | 0.97 | 0.99/0.91/1 | 0.92/1.09/1.03 | The values are within the error limits. |