<PackageReference Include="System.Memory" Version="4.6.0" />

IPinnable

public interface IPinnable
Provides a mechanism for pinning and unpinning objects to prevent the GC from moving them.
MemoryHandle Pin(int elementIndex)

Call this method to indicate that the IPinnable object can not be moved by the garbage collector. The address of the pinned object can be taken. The offset to the element within the memory at which the returned MemoryHandle points to.

void Unpin()

Call this method to indicate that the IPinnable object no longer needs to be pinned. The garbage collector is free to move the object now.