It’s said here, “Starting in .NET 9, the size limit of 1 MiB is enforced.”
So, having the following code with dotnet9:
[InlineArray(1_048_577 /*2^20 + 1*/)]
public struct ByteBuffer
{
private byte _firstElement;
}
...
var buffer = new ByteBuffer();
I expect the following exception:
System.TypeLoadException: Size of field of type ‘ByteBuffer’ from assembly ‘_, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ is too large.
but there isn’t any.
The exception starts to throw when the length of inline array is 2^27:
[InlineArray(134_217_728 /*2^27*/)]
So, I just wonder if I am mistaken or there is a bug in dotnet/runtime or wrong documentation or something
0
The documentation is wrong, or at least out of date.
The limit was 1MiB, but was adjusted to ((1 << 27) - 1) - 6
(a constant known as FIELD_OFFSET_LAST_REAL_OFFSET) at the same time that the issues around sequential structs not being checked was fixed.
The reasoning was that 1MiB is arbitrary. FIELD_OFFSET_LAST_REAL_OFFSET, while also a bit arbitrary, is the limit that CoreCLR places on the maximum size of a struct. So the logic is that the max size you can define a large struct using InlineArray
matches the size you can define it if you use a lot of individual fields.
See this issue for the discussion and reasoning, and this PR for the actual change.
(Found by searching https://github.com/dotnet/runtime for “Size of field of type”)
0