91 lines
2.9 KiB
C#
91 lines
2.9 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace AlicizaX
|
|
{
|
|
/// <summary>
|
|
/// 内存池信息。
|
|
/// </summary>
|
|
[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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 池类型。
|
|
/// </summary>
|
|
public Type Type => _type;
|
|
|
|
/// <summary>
|
|
/// 池中空闲对象数量(可立即借出)。
|
|
/// </summary>
|
|
public int UnusedCount => _unusedCount;
|
|
|
|
/// <summary>
|
|
/// 当前被借出、尚未归还的对象数量。
|
|
/// </summary>
|
|
public int UsingCount => _usingCount;
|
|
|
|
/// <summary>
|
|
/// 累计 Acquire 调用次数(仅开发模式有效)。
|
|
/// </summary>
|
|
public int AcquireCount => _acquireCount;
|
|
|
|
/// <summary>
|
|
/// 累计 Release 调用次数(仅开发模式有效)。
|
|
/// </summary>
|
|
public int ReleaseCount => _releaseCount;
|
|
|
|
/// <summary>
|
|
/// 累计 new T() 创建次数(池不够时的实际分配,仅开发模式有效)。
|
|
/// </summary>
|
|
public int CreateCount => _createCount;
|
|
|
|
/// <summary>
|
|
/// 近期峰值并发使用量。回收策略据此决定保留多少对象。
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|