1
0
mirror of https://github.com/chylex/.NET-Community-Toolkit.git synced 2024-11-24 07:42:45 +01:00
.NET-Community-Toolkit/tests/CommunityToolkit.HighPerformance.UnitTests/Buffers/Internals/TrackingArrayPool{T}.cs
2021-11-01 22:12:56 +01:00

39 lines
1.0 KiB
C#

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Buffers;
using System.Collections.Generic;
namespace CommunityToolkit.HighPerformance.UnitTests.Buffers.Internals;
internal sealed class TrackingArrayPool<T> : ArrayPool<T>
{
private readonly ArrayPool<T> pool = Create();
private readonly HashSet<T[]> arrays = new();
/// <summary>
/// Gets the collection of currently rented out arrays
/// </summary>
public IReadOnlyCollection<T[]> RentedArrays => this.arrays;
/// <inheritdoc/>
public override T[] Rent(int minimumLength)
{
T[] array = this.pool.Rent(minimumLength);
_ = this.arrays.Add(array);
return array;
}
/// <inheritdoc/>
public override void Return(T[] array, bool clearArray = false)
{
_ = this.arrays.Remove(array);
this.pool.Return(array, clearArray);
}
}