Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions csharp/Platform.Collections/Arrays/ArrayPool[T].cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,26 @@ public class ArrayPool<T>
/// <para></para>
/// </summary>
[ThreadStatic]
private static ArrayPool<T> _threadInstance;
private static WeakReference<ArrayPool<T>> _threadInstance;
/// <summary>
/// <para>
/// Gets the thread instance value.
/// </para>
/// <para></para>
/// </summary>
internal static ArrayPool<T> ThreadInstance => _threadInstance ?? (_threadInstance = new ArrayPool<T>());
internal static ArrayPool<T> ThreadInstance
{
get
{
if (_threadInstance?.TryGetTarget(out var instance) == true)
{
return instance;
}
var newInstance = new ArrayPool<T>();
_threadInstance = new WeakReference<ArrayPool<T>>(newInstance);
return newInstance;
}
}
private readonly int _maxArraysPerSize;
private readonly Dictionary<long, Stack<T[]>> _pool = new Dictionary<long, Stack<T[]>>(ArrayPool.DefaultSizesAmount);

Expand Down
Loading