/// <summary>Copies the items in the span to a given destination.</summary> /// <param name="destination">The destination array where the items should be copied.</param> /// <exception cref="ArgumentNullException"><paramref name="destination" /> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><see cref="Length" /> is greater than <paramref name="destination" />.</exception> public void CopyTo(UnmanagedArray <T> destination) { var items = _items; var length = _length; ThrowIfNull(destination, nameof(destination)); ThrowIfNotInInsertBounds(length, destination.Length, nameof(Length), nameof(destination)); CopyArrayUnsafe <T>(destination.GetPointerUnsafe(0), items, length); }
/// <summary>Copies the items in the array to a given destination.</summary> /// <param name="destination">The destination array where the items should be copied.</param> /// <exception cref="ArgumentNullException"><paramref name="destination" /> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><see cref="Length" /> is greater than <paramref name="destination" />.</exception> public void CopyTo(UnmanagedArray <T> destination) { AssertNotNull(this); var items = &_data->Item; var length = _data->Length; ThrowIfNull(destination, nameof(destination)); ThrowIfNotInInsertBounds(length, destination.Length, nameof(Length), nameof(destination)); CopyArrayUnsafe <T>(destination.GetPointerUnsafe(0), items, length); }
/// <summary>Initializes a new instance of the <see cref="UnmanagedSpan{T}" /> struct.</summary> /// <param name="array">The array to create the span for.</param> public UnmanagedSpan(UnmanagedArray <T> array) { if (!array.IsNull) { _length = array.Length; _items = array.GetPointerUnsafe(0); } else { this = Empty; } }
/// <summary>Initializes a new instance of the <see cref="UnmanagedSpan{T}" /> struct.</summary> /// <param name="array">The array to create the span for.</param> /// <param name="start">The index of <paramref name="array" /> at which the span should start.</param> /// <exception cref="ArgumentOutOfRangeException"><paramref name="start" /> is greater than or equal to the length of <paramref name="array" />.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="array" /> is null and <paramref name="start" /> is not <c>zero</c>.</exception> public UnmanagedSpan(UnmanagedArray <T> array, nuint start) { if (!array.IsNull) { ThrowIfNotInBounds(start, array.Length, nameof(start), nameof(array.Length)); _length = array.Length - start; _items = array.GetPointerUnsafe(start); } else { ThrowIfNotZero(start, nameof(start)); this = Empty; } }