com.alicizax.unity.framework/Runtime/ABase/Base/MemoryPool/MemoryPoolInfo.cs

91 lines
2.9 KiB
C#
Raw Normal View History

2026-04-21 14:24:36 +08:00
using System;
2025-10-11 15:18:09 +08:00
using System.Runtime.InteropServices;
namespace AlicizaX
{
/// <summary>
/// 内存池信息。
/// </summary>
[StructLayout(LayoutKind.Auto)]
public struct MemoryPoolInfo
{
private readonly Type _type;
2026-04-21 14:24:36 +08:00
private readonly int _unusedCount;
private readonly int _usingCount;
private readonly int _acquireCount;
private readonly int _releaseCount;
private readonly int _createCount;
private readonly int _highWaterMark;
private readonly int _maxCapacity;
private readonly int _idleFrames;
private readonly int _poolArrayLength;
2025-10-11 15:18:09 +08:00
2026-04-21 14:24:36 +08:00
public MemoryPoolInfo(Type type, int unusedCount, int usingCount,
int acquireCount, int releaseCount, int createCount,
int highWaterMark, int maxCapacity,
int idleFrames, int poolArrayLength)
2025-10-11 15:18:09 +08:00
{
_type = type;
2026-04-21 14:24:36 +08:00
_unusedCount = unusedCount;
_usingCount = usingCount;
_acquireCount = acquireCount;
_releaseCount = releaseCount;
_createCount = createCount;
_highWaterMark = highWaterMark;
_maxCapacity = maxCapacity;
_idleFrames = idleFrames;
_poolArrayLength = poolArrayLength;
2025-10-11 15:18:09 +08:00
}
/// <summary>
2026-04-21 14:24:36 +08:00
/// 池类型。
2025-10-11 15:18:09 +08:00
/// </summary>
2026-04-21 14:24:36 +08:00
public Type Type => _type;
2025-10-11 15:18:09 +08:00
/// <summary>
2026-04-21 14:24:36 +08:00
/// 池中空闲对象数量(可立即借出)。
2025-10-11 15:18:09 +08:00
/// </summary>
2026-04-21 14:24:36 +08:00
public int UnusedCount => _unusedCount;
2025-10-11 15:18:09 +08:00
/// <summary>
2026-04-21 14:24:36 +08:00
/// 当前被借出、尚未归还的对象数量。
2025-10-11 15:18:09 +08:00
/// </summary>
2026-04-21 14:24:36 +08:00
public int UsingCount => _usingCount;
2025-10-11 15:18:09 +08:00
/// <summary>
2026-04-21 14:24:36 +08:00
/// 累计 Acquire 调用次数(仅开发模式有效)。
2025-10-11 15:18:09 +08:00
/// </summary>
2026-04-21 14:24:36 +08:00
public int AcquireCount => _acquireCount;
2025-10-11 15:18:09 +08:00
/// <summary>
2026-04-21 14:24:36 +08:00
/// 累计 Release 调用次数(仅开发模式有效)。
2025-10-11 15:18:09 +08:00
/// </summary>
2026-04-21 14:24:36 +08:00
public int ReleaseCount => _releaseCount;
2025-10-11 15:18:09 +08:00
/// <summary>
2026-04-21 14:24:36 +08:00
/// 累计 new T() 创建次数(池不够时的实际分配,仅开发模式有效)。
2025-10-11 15:18:09 +08:00
/// </summary>
2026-04-21 14:24:36 +08:00
public int CreateCount => _createCount;
2025-10-11 15:18:09 +08:00
/// <summary>
2026-04-21 14:24:36 +08:00
/// 近期峰值并发使用量。回收策略据此决定保留多少对象。
2025-10-11 15:18:09 +08:00
/// </summary>
2026-04-21 14:24:36 +08:00
public int HighWaterMark => _highWaterMark;
/// <summary>
/// 池容量硬上限。超出后 Release 的对象直接丢弃交给 GC。
/// </summary>
public int MaxCapacity => _maxCapacity;
/// <summary>
/// 连续无 Acquire 的帧数。>=300 开始温和回收,>=900 激进回收+高水位衰减。
/// </summary>
public int IdleFrames => _idleFrames;
/// <summary>
/// 底层 T[] 数组的实际长度。反映真实内存占用(含空槽)。
/// </summary>
public int PoolArrayLength => _poolArrayLength;
2025-10-11 15:18:09 +08:00
}
}