static void TryEnsureCapacity(ref T[] array, int index)
 {
     if (array.Length == index)
     {
         ArrayPool <T> .Shared.Return(array, RuntimeHelpersEx.IsReferenceOrContainsReferences <T>());
     }
     array = ArrayPool <T> .Shared.Rent(index * 2);
 }
Пример #2
0
        void EnsureCapacity()
        {
            var newArray = array.AsSpan().ToArray();

            ArrayPool <T> .Shared.Return(array, RuntimeHelpersEx.IsReferenceOrContainsReferences <T>());

            array = newArray;
        }
        public void Dispose()
        {
            if (array != null)
            {
                ArrayPool <T> .Shared.Return(array, RuntimeHelpersEx.IsReferenceOrContainsReferences <T>());

                array = null;
            }
        }
Пример #4
0
        public void DequeueRange(int count)
        {
            lock (SyncRoot)
            {
                var dest = ArrayPool <T> .Shared.Rent(count);

                try
                {
                    for (int i = 0; i < count; i++)
                    {
                        dest[i] = queue.Dequeue();
                    }

                    CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs <T> .Remove(dest.AsSpan(0, count), 0));
                }
                finally
                {
                    ArrayPool <T> .Shared.Return(dest, RuntimeHelpersEx.IsReferenceOrContainsReferences <T>());
                }
            }
        }