ArrayPool<T> replaced with ThreadStaticPools

This commit is contained in:
mlemanczyk committed 2025-11-07 00:46:16 +01:00
1 parent c004e140db
commit 9537addf38
12 files changed
+123 -75

No files matched your search

+37
View File
@@ -3,11 +3,24 @@ using System.Collections.Generic;
using System.Runtime.CompilerServices;
using PerfectNumbers.Core.Cpu;
using PerfectNumbers.Core.Gpu;
using PeterO.Numbers;
namespace PerfectNumbers.Core
{
public readonly struct ThreadStaticPools
{
[ThreadStatic]
private static ArrayPool<EInteger>? _eintegerPool;
public static ArrayPool<EInteger> EIntegerPool
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return _eintegerPool ??= ArrayPool<EInteger>.Create();
}
}
[ThreadStatic]
private static ArrayPool<FactorEntry>? _factorEntryPool;
@@ -32,6 +45,18 @@ namespace PerfectNumbers.Core
}
}
[ThreadStatic]
private static ArrayPool<GpuUInt128>? _gpuUInt128Pool;
public static ArrayPool<GpuUInt128> GpuUInt128Pool
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return _gpuUInt128Pool ??= ArrayPool<GpuUInt128>.Create();
}
}
[ThreadStatic]
private static MersenneCpuDivisorScanSession? _mersenneCpuDivisorSession;
@@ -55,6 +80,18 @@ namespace PerfectNumbers.Core
_mersenneCpuDivisorSession = session;
}
[ThreadStatic]
private static ArrayPool<UInt128>? _uint128Pool;
public static ArrayPool<UInt128> UInt128Pool
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return _uint128Pool ??= ArrayPool<UInt128>.Create();
}
}
[ThreadStatic]
private static ArrayPool<ulong>? _ulongPool;