using System.Collections.Generic;
namespace Thousandto.Core.Base
{
///
/// 数据列表的一个缓存池,对于一些业务不用重复创建List,减少GC
///
///
public class ListPool where T:class
{
//所有回收的列表
List> _items = new List>();
//返回一个空列表
public List New()
{
if (_items.Count > 0)
{
var ret = _items[_items.Count - 1];
_items.RemoveAt(_items.Count - 1);
return ret;
}
return new List();
}
//移除列表
public void Free(List obj)
{
if (obj != null)
{
obj.Clear();
_items.Add(obj);
}
}
//清理到所有缓存
public void Sweep()
{
_items.Clear();
}
//获取当前列表的数量
public int GetCount()
{
return _items.Count;
}
}
}