Closed
Description
C# 7.3 allows pinning spans directly. Pinning empty behaves differently than pinning the ref returned from MemoryMarshal.GetReference
.
static unsafe void PinMe()
{
int[] emptyArray = new int[0];
Span<int> emptySpan = new Span<int>(emptyArray);
fixed (int* ea = emptyArray)
fixed (int* es = emptySpan)
fixed (int* esr = &MemoryMarshal.GetReference(emptySpan))
{
Console.WriteLine($"Array: 0x{(ulong)ea:X}, Span: 0x{(ulong)es:X}, Address of ref span: 0x{(ulong)esr:X}");
}
}
Yields something like:
Array: 0x0, Span: 0x0, Address of ref span: 0x27D97CD1588
cc: @danmosemsft, @jkotas