Exemple #1
0
        public void Set(ReadOnlySpan <T> values)
        {
            if (Length < values.Length)
            {
                throw new ArgumentOutOfRangeException("values");
            }

            // For native memory, use bulk copy
            if (Object == null && values.Object == null)
            {
                var source      = PtrUtils.ComputeAddress(values.Object, values.Offset);
                var destination = PtrUtils.ComputeAddress(Object, Offset);
                var byteCount   = values.Length * PtrUtils.SizeOf <T>();
                PtrUtils.Copy(source, destination, byteCount);
                return;
            }

            for (int i = 0; i < values.Length; i++)
            {
                this[i] = values[i];
            }
        }
Exemple #2
0
        /// <summary>
        /// Copies the contents of this span into another.  The destination
        /// must be at least as big as the source, and may be bigger.
        /// </summary>
        /// <param name="destination">The span to copy items into.</param>
        public bool TryCopyTo(Span <T> destination)
        {
            if (Length > destination.Length)
            {
                return(false);
            }

            // For native memory, use bulk copy
            if (Object == null && destination.Object == null)
            {
                var source         = PtrUtils.ComputeAddress(Object, Offset);
                var destinationPtr = PtrUtils.ComputeAddress(destination.Object, destination.Offset);
                var byteCount      = Length * PtrUtils.SizeOf <T>();
                PtrUtils.Copy(source, destinationPtr, byteCount);
                return(true);
            }

            for (int i = 0; i < Length; i++)
            {
                destination[i] = this[i];
            }
            return(true);
        }