/// <summary> /// 创建对象容器 /// </summary> /// <param name="initSize"></param> private ObjectPoolContainer <T> CreateContainer() { var container = new ObjectPoolContainer <T>(); container.Item = _returnT(); UnUseList.Add(container); return(container); }
/// <summary> /// 从池子中取出对象 /// </summary> /// <returns></returns> public T Get() { ObjectPoolContainer <T> container = null; if (UnUseList.Count > 0) { container = UnUseList[0]; } else { container = CreateContainer(); } container.Consume(); UnUseList.Remove(container); UserDict.Add(container.Item, container); return(container.Item); }