// 从对象池中取出一个对象. public T GetObjectFromPool <T>(int iMaxCount) where T : class, new() { GKObjectPool <T> pool = GetOrCreateObjectPool <T>(iMaxCount, true); if (null == pool) { return(null); } return(pool.Spawn(true)); }
// 回收对象到对象池中. public bool ReleaseObjectByPool <T>(T obj) where T : class, new() { GKObjectPool <T> pool = GetOrCreateObjectPool <T>(-1, false); if (null == pool) { return(false); } return(pool.Recycle(obj)); }
// 创建对象池, 创建完毕后可调用函数, Spawn 与 Recycle进行管理. public GKObjectPool <T> GetOrCreateObjectPool <T> (int iMaxCount, bool bCreateWhenNoFind) where T : class, new () { System.Type tType = typeof(T); object obj = null; if (!_objectPool.TryGetValue(tType, out obj) || null == obj) { GKObjectPool <T> newPool = new GKObjectPool <T>(iMaxCount); _objectPool.Add(tType, newPool); return(newPool); } return(obj as GKObjectPool <T>); }