1
0
mirror of https://github.com/chylex/.NET-Community-Toolkit.git synced 2025-08-16 23:31:47 +02:00
Files
.github
CommunityToolkit.Common
CommunityToolkit.Diagnostics
CommunityToolkit.HighPerformance
CommunityToolkit.Mvvm
CommunityToolkit.Mvvm.SourceGenerators
build
tests
CommunityToolkit.Common.UnitTests
CommunityToolkit.Diagnostics.UnitTests
CommunityToolkit.HighPerformance.UnitTests
Buffers
Internals
TrackingArrayPool{T}.cs
UnmanagedSpanOwner.cs
Test_ArrayPoolBufferWriter{T}.cs
Test_MemoryBufferWriter{T}.cs
Test_MemoryOwner{T}.cs
Test_SpanOwner{T}.cs
Test_StringPool.cs
Enumerables
Extensions
Helpers
Memory
Streams
CommunityToolkit.HighPerformance.UnitTests.csproj
Test_Box{T}.cs
Test_NullableReadOnlyRef{T}.cs
Test_NullableRef{T}.cs
Test_ReadOnlyRef{T}.cs
Test_Ref{T}.cs
CommunityToolkit.Mvvm.DisableINotifyPropertyChanging.UnitTests
CommunityToolkit.Mvvm.ExternalAssembly
CommunityToolkit.Mvvm.Internals.UnitTests
CommunityToolkit.Mvvm.SourceGenerators.UnitTests
CommunityToolkit.Mvvm.UnitTests
.editorconfig
.git-blame-ignore-revs
.gitattributes
.gitignore
.runsettings
CODE_OF_CONDUCT.md
Contributing.md
Directory.Build.props
Directory.Build.targets
License.md
README.md
ThirdPartyNotices.txt
azure-pipelines.yml
dotnet Community Toolkit.sln
toolkit.snk
version.json
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);
}
}