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