示例#1
0
        /// <summary>
        // Writes 'count' structs of type T from 'array' (starting at 'offset') into unmanaged memory.
        /// </summary>
        public void WriteArray <T>(Int64 position, T[] array, Int32 offset, Int32 count) where T : struct
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array), SR.ArgumentNull_Buffer);
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (array.Length - offset < count)
            {
                throw new ArgumentException(SR.Argument_InvalidOffLen);
            }
            Contract.EndContractBlock();

            EnsureSafeToWrite(position, 0);

            UInt32 sizeOfT = SafeBuffer.AlignedSizeOf <T>();

            long  spaceLeft   = _capacity - position;
            ulong spaceNeeded = (ulong)(sizeOfT * count);

            if ((ulong)spaceLeft < spaceNeeded)
            {
                throw new ArgumentException(SR.Argument_NotEnoughBytesToWrite, nameof(position));
            }

            _buffer.WriteArray <T>((UInt64)(_offset + position), array, offset, count);
        }
示例#2
0
        /// <summary>
        /// Extends WriteArray<T> so that buffer offset of 0 and call to Array.Length are not needed.
        /// <example>
        /// safebuffer.WriteArray<T>(byteOffset, array);
        /// </example>
        /// </summary>
        public static void WriteArray <T>(this SafeBuffer safebuffer, UInt64 byteOffset, T[] array) where T : struct
        {
            if (safebuffer == null)
            {
                throw new ArgumentNullException("safebuffer");
            }

            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            safebuffer.WriteArray(byteOffset, array, 0, array.Length);
        }
        [System.Security.SecurityCritical]  // auto-generated_required
        public void WriteArray <T>(Int64 position, T[] array, Int32 offset, Int32 count) where T : struct
        {
            if (array == null)
            {
                throw new ArgumentNullException("array", "Buffer cannot be null.");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (array.Length - offset < count)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_OffsetAndLengthOutOfBounds"));
            }
            if (position < 0)
            {
                throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (position >= Capacity)
            {
                throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired"));
            }
            Contract.EndContractBlock();

            if (!_isOpen)
            {
                throw new ObjectDisposedException("UnmanagedMemoryAccessor", Environment.GetResourceString("ObjectDisposed_ViewAccessorClosed"));
            }
            if (!CanWrite)
            {
                throw new NotSupportedException(Environment.GetResourceString("NotSupported_Writing"));
            }

            _buffer.WriteArray <T>((UInt64)(_offset + position), array, offset, count);
        }
示例#4
0
        // Writes 'count' structs of type T from 'array' (starting at 'offset') into unmanaged memory.
        public void WriteArray <T>(long position, T[] array, int offset, int count) where T : struct
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array), SR.ArgumentNull_Buffer);
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (array.Length - offset < count)
            {
                throw new ArgumentException(SR.Argument_InvalidOffLen);
            }
            if (position < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (position >= Capacity)
            {
                throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired);
            }

            if (!_isOpen)
            {
                throw new ObjectDisposedException(nameof(UnmanagedMemoryAccessor), SR.ObjectDisposed_ViewAccessorClosed);
            }
            if (!_canWrite)
            {
                throw new NotSupportedException(SR.NotSupported_Writing);
            }

            _buffer.WriteArray <T>((ulong)(_offset + position), array, offset, count);
        }
示例#5
0
        // Writes 'count' structs of type T from 'array' (starting at 'offset') into unmanaged memory.


        public void WriteArray <T>(Int64 position, T[] array, Int32 offset, Int32 count) where T : struct
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array), "Buffer cannot be null.");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (array.Length - offset < count)
            {
                throw new ArgumentException(SR.Argument_OffsetAndLengthOutOfBounds);
            }
            if (position < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (position >= Capacity)
            {
                throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired);
            }

            if (!_isOpen)
            {
                throw new ObjectDisposedException("UnmanagedMemoryAccessor", SR.ObjectDisposed_ViewAccessorClosed);
            }
            if (!CanWrite)
            {
                throw new NotSupportedException(SR.NotSupported_Writing);
            }

            _buffer.WriteArray <T>((UInt64)(_offset + position), array, offset, count);
        }
示例#6
0
 public void WriteArray <T> (long position, T [] array, int offset, int count) where T : struct
 {
     buffer.WriteArray((ulong)position, array, offset, count);
 }
示例#7
0
 /// <summary>
 /// Write bytes to a buffer.
 /// </summary>
 /// <param name="buffer">The buffer to write to.</param>
 /// <param name="byte_offset">The byte offset to write to.</param>
 /// <param name="data">The data to write.</param>
 public static void WriteBytes(SafeBuffer buffer, ulong byte_offset, byte[] data)
 {
     buffer.WriteArray(byte_offset, data, 0, data.Length);
 }
示例#8
0
 /// <summary>
 /// Write unicode string.
 /// </summary>
 /// <param name="buffer">The buffer to write to.</param>
 /// <param name="byte_offset">The byte offset to write to.</param>
 /// <param name="value">The string value to write.</param>
 public static void WriteUnicodeString(SafeBuffer buffer, ulong byte_offset, string value)
 {
     char[] chars = value.ToCharArray();
     buffer.WriteArray(byte_offset, chars, 0, chars.Length);
 }
 /// <summary>
 /// Write char array.
 /// </summary>
 /// <param name="buffer">The buffer to write to.</param>
 /// <param name="byte_offset">The byte offset to write to.</param>
 /// <param name="value">The chars to write.</param>
 public static void WriteCharArray(SafeBuffer buffer, ulong byte_offset, char[] value)
 {
     buffer.WriteArray(byte_offset, value, 0, value.Length);
 }