/// <summary> /// Copies the specified number of elements from a one-dimensional array to the current array. /// </summary> /// <param name="source">The source one-dimensional array.</param> /// <param name="srcIndex">The index in the source array at which copying begins.</param> /// <param name="destIndex">The index in the destination array at which copying begins.</param> /// <param name="length">The number of elements to copy</param> public void Copy(T[] source, int srcIndex, int destIndex, int length) { if (this.isReadOnly) { throw new InvalidOperationException("The array is read-only."); } if (srcIndex < 0) { throw new IndexOutOfRangeException("Source index cannot be negative."); } if (source.Length < srcIndex + length) { throw new IndexOutOfRangeException("The specified length is greater than the number of elements from srcIndex to the end of the source array."); } if (destIndex < 0) { throw new IndexOutOfRangeException("Destination index cannot be negative."); } if (this.Length < destIndex + length) { throw new IndexOutOfRangeException("The specified length is greater than the number of elements from destIndex to the end of the destination array."); } MemoryAccess.CopyFromArray(source, srcIndex, this.data + (destIndex * ElementSize), length * ElementSize, length); }
public static void Copy <T>(T[] src, int srcIndex, byte[] dest, int destIndex, int length) where T : struct { if (destIndex < 0) { throw new IndexOutOfRangeException(); } fixed(void *start = dest) { MemoryAccess.CopyFromArray(src, srcIndex, (IntPtr)start + destIndex, dest.Length - destIndex, length); } }
/// <summary> /// Copies a specified number of items from a array starting at a particular index into a destination buffer starting at a particular offset. /// Similar to <see cref="System.Buffer.BlockCopy(Array, int, Array, int, int)"/>, but works for any simple struct, not just primitive types. /// </summary> /// <typeparam name="T">The type of the simple value type to copy.</typeparam> /// <param name="src">The source array to copy from.</param> /// <param name="srcIndex">The zero-based byte index into src from which copying begins.</param> /// <param name="dest">The destination buffer.</param> /// <param name="destIndex">The zero-based offset in the destination buffer at which copying begins.</param> /// <param name="length">The number of elements to copy.</param> public static void Copy <T>(T[] src, int srcIndex, IntPtr dest, int destIndex, int length) where T : struct => MemoryAccess.CopyFromArray(src, srcIndex, (IntPtr)dest + destIndex, length * MemoryAccess.SizeOf <T>(), length);