update
This commit is contained in:
parent
3788d001ba
commit
24bb3f9e94
@ -73,7 +73,7 @@ namespace AlicizaX
|
||||
if (item == null) return;
|
||||
|
||||
s_ReleaseCount++;
|
||||
// 防止 ClearAll 后 Release 导致负数
|
||||
|
||||
if (s_CurrentInUse > 0)
|
||||
s_CurrentInUse--;
|
||||
|
||||
@ -96,7 +96,6 @@ namespace AlicizaX
|
||||
if (frameCount == s_LastTickFrame) return;
|
||||
s_LastTickFrame = frameCount;
|
||||
|
||||
// 更新高水位:基于实际并发使用量(在外对象数),而非单帧 Acquire 次数
|
||||
if (s_PeakInUse > s_HighWaterMark)
|
||||
s_HighWaterMark = s_PeakInUse;
|
||||
|
||||
@ -109,7 +108,6 @@ namespace AlicizaX
|
||||
|
||||
if (s_Count <= MIN_KEEP) return;
|
||||
|
||||
// ---- 双阶段渐进回收 ----
|
||||
if (s_IdleFrames >= IDLE_THRESHOLD)
|
||||
{
|
||||
int target = Math.Max((int)(s_HighWaterMark * 1.5f), MIN_KEEP);
|
||||
@ -117,7 +115,7 @@ namespace AlicizaX
|
||||
if (s_Count > target)
|
||||
{
|
||||
int excess = s_Count - target;
|
||||
// 阶段1:温和回收 / 阶段2:激进回收
|
||||
|
||||
float ratio = s_IdleFrames < IDLE_AGGRESSIVE ? 0.25f : 0.5f;
|
||||
int removeCount = Math.Max((int)(excess * ratio), 1);
|
||||
|
||||
@ -159,9 +157,7 @@ namespace AlicizaX
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 预热池,启动时调用避免运行时 GC。
|
||||
/// </summary>
|
||||
|
||||
public static void Prewarm(int count)
|
||||
{
|
||||
count = Math.Min(count, s_MaxCapacity);
|
||||
@ -181,9 +177,6 @@ namespace AlicizaX
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 缩容:场景切换时调用,释放多余内存。
|
||||
/// </summary>
|
||||
public static void Shrink(int keepCount)
|
||||
{
|
||||
if (keepCount >= s_Count) return;
|
||||
|
||||
@ -4,10 +4,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace AlicizaX
|
||||
{
|
||||
/// <summary>
|
||||
/// 内存池注册表。非泛型路径通过此表查找对应的泛型池。
|
||||
/// 注册发生在 MemoryPool<T> 静态构造器中,仅一次。
|
||||
/// </summary>
|
||||
|
||||
public static class MemoryPoolRegistry
|
||||
{
|
||||
internal sealed class MemoryPoolHandle
|
||||
@ -63,7 +60,6 @@ namespace AlicizaX
|
||||
if (s_Handles.TryGetValue(type, out var handle))
|
||||
return handle.Acquire();
|
||||
|
||||
// 首次访问:触发 MemoryPool<T> 静态构造器
|
||||
RuntimeHelpers.RunClassConstructor(
|
||||
typeof(MemoryPool<>).MakeGenericType(type).TypeHandle);
|
||||
|
||||
@ -85,7 +81,6 @@ namespace AlicizaX
|
||||
return;
|
||||
}
|
||||
|
||||
// 首次访问:触发静态构造器
|
||||
RuntimeHelpers.RunClassConstructor(
|
||||
typeof(MemoryPool<>).MakeGenericType(type).TypeHandle);
|
||||
|
||||
@ -138,9 +133,7 @@ namespace AlicizaX
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每帧由 MemoryPoolTicker 调用,驱动所有池的自动回收。
|
||||
/// </summary>
|
||||
|
||||
public static void TickAll(int frameCount)
|
||||
{
|
||||
if (s_TickArrayDirty)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user