/// <summary>Initializes a new instance of the <see cref="UnmanagedValueStack{T}" /> struct.</summary> /// <param name="span">The span that is used to populate the stack.</param> /// <param name="alignment">The alignment, in bytes, of the items in the stack or <c>zero</c> to use the system default.</param> /// <exception cref="ArgumentOutOfRangeException"><paramref name="alignment" /> is not a <c>power of two</c>.</exception> public UnmanagedValueStack(UnmanagedReadOnlySpan <T> span, nuint alignment = 0) { if (span.Length != 0) { var items = new UnmanagedArray <T>(span.Length, alignment); CopyArrayUnsafe(items.GetPointerUnsafe(0), span.GetPointerUnsafe(0), span.Length); _items = items; } else { if (alignment != 0) { ThrowIfNotPow2(alignment); } _items = UnmanagedArray <T> .Empty; } _count = span.Length; }
/// <summary>Initializes a new instance of the <see cref="UnmanagedValueList{T}" /> struct.</summary> /// <param name="span">The span that is used to populate the list.</param> /// <param name="alignment">The alignment, in bytes, of the items in the list or <c>zero</c> to use the system default.</param> /// <exception cref="ArgumentOutOfRangeException"><paramref name="alignment" /> is not a <c>power of two</c>.</exception> public unsafe UnmanagedValueList(UnmanagedReadOnlySpan <T> span, nuint alignment = 0) { if (span.Length != 0) { var items = new UnmanagedArray <T>(span.Length, alignment, zero: false); CopyArrayUnsafe <T>(items.GetPointerUnsafe(0), span.GetPointerUnsafe(0), span.Length); _items = items; } else { if (alignment != 0) { ThrowIfNotPow2(alignment, nameof(alignment)); } _items = UnmanagedArray <T> .Empty; } _count = span.Length; _version = 0; }