public static unsafe void CreateFromPinnedArrayIntReadOnlyMemorySliceRemainsPinned() { int[] a = { 90, 91, 92, 93, 94, 95, 96, 97, 98 }; ReadOnlyMemory <int> pinnedMemory = MemoryMarshal.CreateFromPinnedArray(a, 3, 5); pinnedMemory.Validate(93, 94, 95, 96, 97); TestMemory <int> testPinnedMemory = Unsafe.As <ReadOnlyMemory <int>, TestMemory <int> >(ref pinnedMemory); ReadOnlyMemory <int> slice = pinnedMemory.Slice(0); TestMemory <int> testSlice = Unsafe.As <ReadOnlyMemory <int>, TestMemory <int> >(ref slice); Assert.Equal(testPinnedMemory._index, testSlice._index); Assert.Equal(testPinnedMemory._length, testSlice._length); slice = pinnedMemory.Slice(0, pinnedMemory.Length); testSlice = Unsafe.As <ReadOnlyMemory <int>, TestMemory <int> >(ref slice); Assert.Equal(testPinnedMemory._index, testSlice._index); Assert.Equal(testPinnedMemory._length, testSlice._length); int expectedLength = testPinnedMemory._length - 1; slice = pinnedMemory.Slice(1); testSlice = Unsafe.As <ReadOnlyMemory <int>, TestMemory <int> >(ref slice); Assert.Equal(testPinnedMemory._index + 1, testSlice._index); Assert.Equal(expectedLength, testSlice._length); expectedLength = 2 | (1 << 31); slice = pinnedMemory.Slice(1, 2); testSlice = Unsafe.As <ReadOnlyMemory <int>, TestMemory <int> >(ref slice); Assert.Equal(testPinnedMemory._index + 1, testSlice._index); Assert.Equal(expectedLength, testSlice._length); }
public static void CreateFromPinnedArrayIntReadOnlyMemorySliceRemainsPinned() { int[] a = { 90, 91, 92, 93, 94, 95, 96, 97, 98 }; ReadOnlyMemory <int> pinnedMemory = MemoryMarshal.CreateFromPinnedArray(a, 3, 5); pinnedMemory.Validate(93, 94, 95, 96, 97); ReadOnlyMemory <int> slice = pinnedMemory.Slice(0); TestMemory <int> testSlice = Unsafe.As <ReadOnlyMemory <int>, TestMemory <int> >(ref slice); Assert.Equal(3 | (1 << 31), testSlice._index); Assert.Equal(5, testSlice._length); slice = pinnedMemory.Slice(0, pinnedMemory.Length); testSlice = Unsafe.As <ReadOnlyMemory <int>, TestMemory <int> >(ref slice); Assert.Equal(3 | (1 << 31), testSlice._index); Assert.Equal(5, testSlice._length); slice = pinnedMemory.Slice(1); testSlice = Unsafe.As <ReadOnlyMemory <int>, TestMemory <int> >(ref slice); Assert.Equal(4 | (1 << 31), testSlice._index); Assert.Equal(4, testSlice._length); slice = pinnedMemory.Slice(1, 2); testSlice = Unsafe.As <ReadOnlyMemory <int>, TestMemory <int> >(ref slice); Assert.Equal(4 | (1 << 31), testSlice._index); Assert.Equal(2, testSlice._length); }
static void Main(string[] args) { Options arguments = new Options(args); if (arguments.showTest) { Console.WriteLine("RUNNING UNIT TESTS ..."); TestMemory.runTests(); //TestCPU.runtTests(); TestRegisters.runTests(); TestBarrelShifter.runTests(); TestDecodeExecuteSimI.runTests(); TestDecodeExecuteSimII.runTests(); Console.WriteLine("All UNIT TESTS passed! Exiting ..."); Environment.Exit(0); } // subject and observers. Observers computer and form1 add themselves to the collection of observers and hold an object reference to it. Subject subject = new Subject(); Computer computer = new Computer(subject, arguments); // preset to launch form Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // create a form and launch it ArmSimForm form = new ArmSimForm(subject, computer, arguments); Application.Run(form); }