Microsoft recommends in Write safe and efficient C# code:
Apply the
in
modifier toreadonly struct
parameters larger thanSystem.IntPtr.Size
Is there a simple way to check the managed memory size of a ref struct like ReadOnlySpan<byte>
?
The following methods don't work:
// CS0208 Cannot get the size of a managed type
unsafe { size = sizeof(ReadOnlySpan<byte>); }
// CS0306 The type 'ReadOnlySpan<byte>' may not be used as a type argument
size = Marshal.SizeOf(default(ReadOnlySpan<byte>));
// ArgumentException "must not be a generic type definition"
size = Marshal.SizeOf(typeof(ReadOnlySpan<byte>));