public int ReadArray<T>(long position, T[] array, int offset, int 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 (!this.CanRead)
     {
         if (!this._isOpen)
         {
             throw new ObjectDisposedException("UnmanagedMemoryAccessor", Environment.GetResourceString("ObjectDisposed_ViewAccessorClosed"));
         }
         throw new NotSupportedException(Environment.GetResourceString("NotSupported_Reading"));
     }
     if (position < 0L)
     {
         throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
     }
     uint num = Marshal.AlignedSizeOf<T>();
     if (position >= this._capacity)
     {
         throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired"));
     }
     int num2 = count;
     long num3 = this._capacity - position;
     if (num3 < 0L)
     {
         num2 = 0;
     }
     else
     {
         ulong num4 = (ulong) (num * count);
         if (num3 < num4)
         {
             num2 = (int) (num3 / ((ulong) num));
         }
     }
     this._buffer.ReadArray<T>((ulong) (this._offset + position), array, offset, num2);
     return num2;
 }
예제 #2
0
        [System.Security.SecurityCritical]  // auto-generated_required
        public int ReadArray <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"));
            }
            Contract.EndContractBlock();
            if (!CanRead)
            {
                if (!_isOpen)
                {
                    throw new ObjectDisposedException("UnmanagedMemoryAccessor", Environment.GetResourceString("ObjectDisposed_ViewAccessorClosed"));
                }
                else
                {
                    throw new NotSupportedException(Environment.GetResourceString("NotSupported_Reading"));
                }
            }
            if (position < 0)
            {
                throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }

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

            // only check position and ask for fewer Ts if count is too big
            if (position >= _capacity)
            {
                throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired"));
            }

            int n          = count;
            long spaceLeft = _capacity - position;

            if (spaceLeft < 0)
            {
                n = 0;
            }
            else
            {
                ulong spaceNeeded = (ulong)(sizeOfT * count);
                if ((ulong)spaceLeft < spaceNeeded)
                {
                    n = (int)(spaceLeft / sizeOfT);
                }
            }

            _buffer.ReadArray <T>((UInt64)(_offset + position), array, offset, n);

            return(n);
        }