Esempio n. 1
0
 /// <summary>
 /// Ensures that the underlying id queue can hold at least a certain number of ids.
 /// </summary>
 /// <param name="count">Number of elements to preallocate space for in the available ids queue.</param>
 /// <param name="pool">Pool to pull resized spans from.</param>
 public void EnsureCapacity(int count, IUnmanagedMemoryPool pool)
 {
     if (!availableIds.Allocated)
     {
         //If this was disposed, we must explicitly rehydrate it.
         this = new IdPool(count, pool);
     }
     else
     {
         if (availableIds.Length < count)
         {
             InternalResize(count, pool);
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Resizes the underlying buffer to the smallest size required to hold the given count and the current available id count.
 /// </summary>
 /// <param name="count">Number of elements to guarantee space for in the available ids queue.</param>
 public void Resize(int count, IUnmanagedMemoryPool pool)
 {
     if (!availableIds.Allocated)
     {
         //If this was disposed, we must explicitly rehydrate it.
         this = new IdPool(count, pool);
     }
     else
     {
         var targetLength = BufferPool.GetCapacityForCount <int>(Math.Max(count, availableIdCount));
         if (availableIds.Length != targetLength)
         {
             InternalResize(targetLength, pool);
         }
     }
 }
Esempio n. 3
0
            public PowerPool(int power, int minimumBlockSize, int expectedPooledCount)
            {
                Power = power;
                SuballocationSize = 1 << power;

                BlockSize = Math.Max(SuballocationSize, minimumBlockSize);
                IdPool<Array<int>>.Create(new PassthroughArrayPool<int>(), expectedPooledCount, out Slots);
                SuballocationsPerBlock = BlockSize / SuballocationSize;
                SuballocationsPerBlockShift = SpanHelper.GetContainingPowerOf2(SuballocationsPerBlock);
                SuballocationsPerBlockMask = (1 << SuballocationsPerBlockShift) - 1;
                Blocks = new Block[1];
                BlockCount = 0;

#if DEBUG
                outstandingIds = new HashSet<int>();
#if LEAKDEBUG
                outstandingAllocators = new Dictionary<string, HashSet<int>>();
#endif
#endif
            }
Esempio n. 4
0
 public static void Create <TPool>(TPool pool, int initialCapacity, out IdPool <TSpan> idPool) where TPool : IMemoryPool <int, TSpan>
 {
     idPool.nextIndex = 0;
     QuickList <int, TSpan> .Create(pool, initialCapacity, out idPool.AvailableIds);
 }
Esempio n. 5
0
 public static void Create <TPool>(TPool pool, int initialCapacity, out IdPool <TSpan> idPool) where TPool : IMemoryPool <int, TSpan>
 {
     idPool.nextIndex        = 0;
     idPool.availableIdCount = 0;
     pool.Take(initialCapacity, out idPool.availableIds);
 }