示例#1
0
        /// <summary>
        /// Gets the freelist for the specified bucket.
        /// Create the freelist if there isn't one.
        /// </summary>
        /// <param name="bucketedSize">The bucket size.</param>
        /// <returns>The freelist for the bucket.</returns>
        internal Bucket <T> GetBucket(int bucketedSize)
        {
            lock (_poolGate)
            {
                // Get an existing bucket
                Bucket <T> bucket = default(Bucket <T>);
                Buckets.TryGetValue(bucketedSize, out bucket);
                if (bucket != null || !_allowNewBuckets)
                {
                    return(bucket);
                }

                // Create a new bucket
#if DEBUG_MEMORY_POOL
                Debug.WriteLine($"Creating new bucket { bucketedSize }");
#endif // DEBUG_MEMORY_POOL
                Bucket <T> newBucket = NewBucket(bucketedSize);
                Buckets.Add(bucketedSize, newBucket);
                return(newBucket);
            }
        }