/// <summary> /// Initializes a new instance of the <see cref="FixedSizeBucket{T}" /> class. /// </summary> public FixedSizeBucket(IEnumerable <T> source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } var collection = source as ICollection <T>; _entries = ArrayReservoir <object> .GetArray(collection?.Count ?? 64); Capacity = _entries.Length; foreach (var item in source) { if (_count == Capacity) { var old = _entries; _entries = ArrayReservoir <object> .GetArray(Capacity << 1); if (old != null) { Array.Copy(old, 0, _entries, 0, _count); ArrayReservoir <object?> .DonateArray(old); } Capacity = _entries.Length; } _entries[_count] = (object?)item ?? BucketHelper.Null; _count++; } }
private static void Leave(Branch[] branches, int resultCount) { for (int index = 0; index < resultCount; index++) { var branch = branches[index]; Interlocked.Decrement(ref branch._useCount); } ArrayReservoir <Branch> .DonateArray(branches); }
private void RecyclePrivate() { ArrayReservoir <object> .DonateArray(_entries); _entries = null; }