StructureOfArraysGenerator icon indicating copy to clipboard operation
StructureOfArraysGenerator copied to clipboard

Use different arrays for each field

Open SupinePandora43 opened this issue 2 years ago • 1 comments

as an option

[MultiArray(typeof(Vector3), IndividualArrays = true)]
public readonly partial struct Vector3MultiArray
{
}
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Auto)]
partial struct Vector3MultiArray : global::StructureOfArraysGenerator.IMultiArray<Vector3MultiArray>
{
-   readonly byte[] __value;
+   readonly float[] __valueX;
+   readonly float[] __valueY;
+   readonly float[] __valueZ;
    readonly int __length;
-   readonly int __byteSize;
-   readonly int __byteOffsetX;
-   readonly int __byteOffsetY;
-   readonly int __byteOffsetZ;

    public int Length => __length;
-   public Span<float> X => MemoryMarshal.CreateSpan(ref Unsafe.As<byte, float>(ref Unsafe.Add(ref GetArrayDataReference(__value), __byteOffsetX)), __length);
-   public Span<float> Y => MemoryMarshal.CreateSpan(ref Unsafe.As<byte, float>(ref Unsafe.Add(ref GetArrayDataReference(__value), __byteOffsetY)), __length);
-   public Span<float> Z => MemoryMarshal.CreateSpan(ref Unsafe.As<byte, float>(ref Unsafe.Add(ref GetArrayDataReference(__value), __byteOffsetZ)), __length);
+   public Span<float> X => __valueX;
+   public Span<float> Y => __valueY;
+   public Span<float> Z => __valueZ;

...

}

this will allow to have more than 2^(32-1)/sizeof(T) elements in a single array.

SupinePandora43 avatar Jan 02 '24 14:01 SupinePandora43

It's hard to see a use case where we have so many elements in use simultaneously. Maybe segments (chunks) could be a better solution, as the Parquet format does.

VoilaNeighbor avatar Jan 04 '24 06:01 VoilaNeighbor

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jul 03 '24 00:07 github-actions[bot]