Example #1
0
        internal DefaultArrayPool(int maxLength, int arraysPerBucket)
        {
            if (maxLength <= 0)
            {
                throw new ArgumentOutOfRangeException("maxLength");
            }
            if (arraysPerBucket <= 0)
            {
                throw new ArgumentOutOfRangeException("arraysPerBucket");
            }

            // Our bucketing algorithm has a minimum length of 16
            if (maxLength < MinimumArrayLength)
            {
                maxLength = MinimumArrayLength;
            }

            int maxBuckets = Utilities.SelectBucketIndex(maxLength);

            _buckets = new DefaultArrayPoolBucket <T> [maxBuckets + 1];
            for (int i = 0; i < _buckets.Length; i++)
            {
                _buckets[i] = new DefaultArrayPoolBucket <T>(Utilities.GetMaxSizeForBucket(i), arraysPerBucket, Utilities.GetPoolId(this));
            }
        }
Example #2
0
 internal static int GetBucketId <T>(DefaultArrayPoolBucket <T> bucket)
 {
     return(bucket.GetHashCode());
 }