using System; namespace AlicizaX { /// /// 内存池。保留旧 API 签名,内部转发到 MemoryPool<T> / MemoryPoolRegistry。 /// public static partial class MemoryPool { private static bool _enableStrictCheck; /// /// 获取或设置是否开启强制检查。 /// public static bool EnableStrictCheck { get => _enableStrictCheck; set => _enableStrictCheck = value; } /// /// 获取内存池的数量。 /// public static int Count => MemoryPoolRegistry.Count; /// /// 获取所有内存池的信息。 /// public static MemoryPoolInfo[] GetAllMemoryPoolInfos() { return MemoryPoolRegistry.GetAllInfos(); } /// /// 清除所有内存池。 /// public static void ClearAll() { MemoryPoolRegistry.ClearAll(); } /// /// 从内存池获取内存对象。 /// public static T Acquire() where T : class, IMemory, new() { return MemoryPool.Acquire(); } /// /// 从内存池获取内存对象。 /// public static IMemory Acquire(Type memoryType) { return MemoryPoolRegistry.Acquire(memoryType); } /// /// 将内存对象归还内存池。 /// public static void Release(IMemory memory) { MemoryPoolRegistry.Release(memory); } /// /// 向内存池中预热指定数量的内存对象。 /// public static void Add(int count) where T : class, IMemory, new() { MemoryPool.Prewarm(count); } /// /// 向内存池中预热指定数量的内存对象。 /// public static void Add(Type memoryType, int count) { MemoryPoolRegistry.Prewarm(memoryType, count); } /// /// 从内存池中移除指定数量的内存对象。 /// public static void Remove(int count) where T : class, IMemory, new() { int target = MemoryPool.UnusedCount - count; MemoryPool.Shrink(target); } /// /// 从内存池中移除指定数量的内存对象。 /// public static void Remove(Type memoryType, int count) { MemoryPoolRegistry.RemoveFromType(memoryType, count); } /// /// 从内存池中移除所有的内存对象。 /// public static void RemoveAll() where T : class, IMemory, new() { MemoryPool.ClearAll(); } /// /// 从内存池中移除所有的内存对象。 /// public static void RemoveAll(Type memoryType) { MemoryPoolRegistry.ClearType(memoryType); } } }