Slide 21
Slide 21 text
T[] where T : unmanaged
C#の配列は要素がunmanaged型(参照型を含まない
struct)の場合、全て直列に並ぶ
new int[] { 1, 2, 3, 4, 5 }
var srcLength = Unsafe.SizeOf() * value.Length;
var allocSize = srcLength + 4;
ref var dest = ref GetSpanReference(allocSize);
ref var src = ref Unsafe.As(ref GetArrayDataReference(value));
Unsafe.WriteUnaligned(ref dest, value.Length);
Unsafe.CopyBlockUnaligned(ref Unsafe.Add(ref dest, 4), ref src, (uint)srcLength);
Advance(allocSize);
Serialize == メモリコピー