public unsafe void CopyFromCopyToFail() { Assert.Throws <ArgumentException>(() => _fixedArrayPtr.CopyTo(new AdventurePhysics[0], 1)); // Too big for destinationArray. Assert.Throws <ArgumentException>(() => _fixedArrayPtr.CopyTo(new AdventurePhysics[100], 100)); // Too big for source FixedPtrArray Assert.Throws <ArgumentException>(() => _fixedArrayPtr.CopyFrom(new AdventurePhysics[0], 1)); // Too big for sourceArray Assert.Throws <ArgumentException>(() => _fixedArrayPtr.CopyFrom(new AdventurePhysics[100], 100)); // Too big for destination FixedPtrArray }
public unsafe void CopyFromCopyTo() { // Allocate array space for a copy and create a new fixed pointer to it. IntPtr copyPtr = _currentProcess.Allocate(_fixedArrayPtr.ArraySize); var arrayCopyPtr = new FixedArrayPtr <AdventurePhysics>((ulong)copyPtr, _fixedArrayPtr.Count); // Copy from original to new array. AdventurePhysics[] physicsArray = new AdventurePhysics[_fixedArrayPtr.Count]; _fixedArrayPtr.CopyTo(physicsArray, _fixedArrayPtr.Count); arrayCopyPtr.CopyFrom(physicsArray, physicsArray.Length); // Check both copies are identical. for (int x = 0; x < physicsArray.Length; x++) { _fixedArrayPtr.Get(out var physicsOriginal, x); arrayCopyPtr.Get(out var physicsCopied, x); if (!physicsOriginal.Equals(physicsCopied)) { Assert.True(false, "All array entries between the two fixed array pointers should be equal."); } } // Cleanup _currentProcess.Free(copyPtr); }