public void NoDispose() { var pinnable = new Pinnable <DisposeChecker>(new DisposeChecker()); pinnable.Dispose(); Assert.Equal(0, pinnable.Value.Disposed); pinnable.Value.Dispose(); Assert.Equal(1, pinnable.Value.Disposed); }
public unsafe void Pin() { var pinnable = new Pinnable <int>(0); for (int x = 0; x < 100; x++) { pinnable.Value = x; Assert.Equal(pinnable.Value, *pinnable.Pointer); } pinnable.Dispose(); }
public unsafe void PinArray() { int[] integers = { 0, 1, 2, 3, 4, 5, 6 }; var pinnable = new Pinnable <int>(integers); // Integers are on the heap, should be pinned by reference. for (int x = 0; x < integers.Length; x++) { integers[x] = 100 + x; Assert.Equal(integers[x], pinnable.Pointer[x]); } pinnable.Dispose(); }
public unsafe void PinArray() { int[] integers = { 0, 1, 2, 3, 4, 5, 6 }; var pinnable = new Pinnable <int>(integers); // Integers are on the heap, should be pinned by reference. for (int x = 0; x < integers.Length; x++) { // in .NET 5 and later, array is copied to Pinned Object Heap. #if !NET5_0_OR_GREATER integers[x] = 100 + x; #endif Assert.Equal(integers[x], pinnable.Pointer[x]); } pinnable.Dispose(); }