Esempio n. 1
0
 public override Span <byte> AsSpan(int index, int length)
 {
     if (IsDisposed)
     {
         BufferPrimitivesThrowHelper.ThrowObjectDisposedException(nameof(ManagedBufferPool));
     }
     return(new Span <byte>(_array, index, length));
 }
Esempio n. 2
0
 public override Span <byte> AsSpan(int index, int length)
 {
     if (IsDisposed)
     {
         BufferPrimitivesThrowHelper.ThrowObjectDisposedException(nameof(OwnedBuffer));
     }
     return(_array.AsSpan().Slice(index, length));
 }
Esempio n. 3
0
 public override void Release()
 {
     if (!IsRetained)
     {
         BufferPrimitivesThrowHelper.ThrowInvalidOperationException();
     }
     Interlocked.Decrement(ref _referenceCount);
 }
Esempio n. 4
0
 public override Span <T> AsSpan(int index, int length)
 {
     if (IsDisposed)
     {
         BufferPrimitivesThrowHelper.ThrowObjectDisposedException(nameof(CustomBuffer));
     }
     return(new Span <T>(_array, index, length));
 }
Esempio n. 5
0
 public virtual Span <T> AsSpan()
 {
     if (IsDisposed)
     {
         BufferPrimitivesThrowHelper.ThrowObjectDisposedException(nameof(OwnedBuffer <T>));
     }
     return(AsSpan(0, Length));
 }
Esempio n. 6
0
 public override void Retain()
 {
     if (IsDisposed)
     {
         BufferPrimitivesThrowHelper.ThrowObjectDisposedException(nameof(ArrayPoolBuffer));
     }
     Interlocked.Increment(ref _referenceCount);
 }
Esempio n. 7
0
 public override Span <T> AsSpan()
 {
     if (IsDisposed)
     {
         BufferPrimitivesThrowHelper.ThrowObjectDisposedException(nameof(OwnedArray <T>));
     }
     return(new Span <T>(_array, 0, _array.Length));
 }
Esempio n. 8
0
 public OwnedArray(T[] array)
 {
     if (array == null)
     {
         BufferPrimitivesThrowHelper.ThrowArgumentNullException(nameof(array));
     }
     _array = array;
 }
 public override void Retain()
 {
     if (IsDisposed)
     {
         BufferPrimitivesThrowHelper.ThrowInvalidOperationException();
     }
     Interlocked.Increment(ref _referenceCount);
 }
Esempio n. 10
0
 protected internal override bool TryGetArray(out ArraySegment <T> arraySegment)
 {
     if (IsDisposed)
     {
         BufferPrimitivesThrowHelper.ThrowObjectDisposedException(nameof(OwnedArray <T>));
     }
     arraySegment = new ArraySegment <T>(_array);
     return(true);
 }
Esempio n. 11
0
 protected override bool TryGetArray(out ArraySegment <T> buffer)
 {
     if (IsDisposed)
     {
         BufferPrimitivesThrowHelper.ThrowObjectDisposedException(nameof(AutoDisposeBuffer <T>));
     }
     buffer = new ArraySegment <T>(_array);
     return(true);
 }
Esempio n. 12
0
        public Buffer <T> Slice(int start)
        {
            if ((uint)start > (uint)_length)
            {
                BufferPrimitivesThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
            }

            return(new Buffer <T>(_owner, _array, _index + start, _length - start));
        }
Esempio n. 13
0
        public ReadOnlyBuffer <T> Slice(int start, int length)
        {
            if ((uint)start > (uint)_length || (uint)length > (uint)(_length - start))
            {
                BufferPrimitivesThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
            }

            return(new ReadOnlyBuffer <T>(_owner, _array, _index + start, length));
        }
Esempio n. 14
0
 protected override bool TryGetArrayInternal(out ArraySegment <byte> buffer)
 {
     if (IsDisposed)
     {
         BufferPrimitivesThrowHelper.ThrowObjectDisposedException(nameof(OwnedBuffer));
     }
     buffer = new ArraySegment <byte>(_array);
     return(true);
 }
Esempio n. 15
0
 protected internal override bool TryGetArrayInternal(out ArraySegment <T> buffer)
 {
     if (IsDisposed)
     {
         BufferPrimitivesThrowHelper.ThrowObjectDisposedException(nameof(OwnerEmptyMemory <T>));
     }
     buffer = new ArraySegment <T>(s_empty);
     return(true);
 }
Esempio n. 16
0
 protected override bool TryGetArray(out ArraySegment <byte> arraySegment)
 {
     if (IsDisposed)
     {
         BufferPrimitivesThrowHelper.ThrowObjectDisposedException(nameof(ManagedBufferPool));
     }
     arraySegment = new ArraySegment <byte>(_array);
     return(true);
 }
Esempio n. 17
0
        public ReadOnlyBuffer(T[] array)
        {
            if (array == null)
            {
                BufferPrimitivesThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }

            _arrayOrOwnedBuffer = array;
            _index  = 0;
            _length = array.Length;
        }
Esempio n. 18
0
        public override bool Release()
        {
            int newRefCount = Interlocked.Decrement(ref _referenceCount);

            if (newRefCount < 0)
            {
                BufferPrimitivesThrowHelper.ThrowInvalidOperationException();
            }
            if (newRefCount == 0)
            {
                OnNoReferences();
                return(false);
            }
            return(true);
        }
Esempio n. 19
0
        public Buffer(T[] array)
        {
            if (array == null)
            {
                BufferPrimitivesThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (default(T) == null && array.GetType() != typeof(T[]))
            {
                BufferPrimitivesThrowHelper.ThrowArrayTypeMismatchException(typeof(T));
            }

            _arrayOrOwnedBuffer = array;
            _index  = 0;
            _length = array.Length;
        }
Esempio n. 20
0
        public ReadOnlyBuffer(T[] array, int start, int length)
        {
            if (array == null)
            {
                BufferPrimitivesThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
            {
                BufferPrimitivesThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
            }

            _arrayOrOwnedBuffer = array;
            _index  = start;
            _length = length;
        }
Esempio n. 21
0
        public ReadOnlyBuffer <T> Slice(int start, int length)
        {
            if ((uint)start > (uint)_length || (uint)length > (uint)(_length - start))
            {
                BufferPrimitivesThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
            }

            // There is no need to 'and' _index by the bit mask here
            // since the constructor will set the highest order bit again anyway
            if (_index < 0)
            {
                return(new ReadOnlyBuffer <T>(Unsafe.As <OwnedBuffer <T> >(_arrayOrOwnedBuffer), _index + start, length));
            }
            return(new ReadOnlyBuffer <T>(Unsafe.As <T[]>(_arrayOrOwnedBuffer), _index + start, length));
        }
Esempio n. 22
0
        public Buffer(T[] array, int start, int length)
        {
            if (array == null)
            {
                BufferPrimitivesThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (default(T) == null && array.GetType() != typeof(T[]))
            {
                BufferPrimitivesThrowHelper.ThrowArrayTypeMismatchException(typeof(T));
            }
            if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
            {
                BufferPrimitivesThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
            }

            _arrayOrOwnedBuffer = array;
            _index  = start;
            _length = length;
        }
Esempio n. 23
0
        public ReadOnlyBuffer(T[] array, int start)
        {
            if (array == null)
            {
                BufferPrimitivesThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }

            int arrayLength = array.Length;

            if ((uint)start > (uint)arrayLength)
            {
                BufferPrimitivesThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
            }

            _array  = array;
            _owner  = null;
            _index  = start;
            _length = arrayLength - start;
        }