diff --git a/ObjectPool.cs b/ObjectPool.cs index 812ee3e..d7c8b06 100644 --- a/ObjectPool.cs +++ b/ObjectPool.cs @@ -13,16 +13,16 @@ namespace KBEngine /// 对象类型 public class ObjectPool where T : new() { - private static LinkedList _objects = new LinkedList(); - + private static Stack _objects = new Stack(); + private static T v; + public static T createObject() { lock (_objects) { - if (_objects.First != null) + if (_objects.Count > 0) { - T v = _objects.First.Value; - _objects.RemoveFirst(); + v = _objects.Pop(); return v; } else @@ -36,7 +36,7 @@ public static void reclaimObject(T item) { lock (_objects) { - _objects.AddLast(item); + _objects.Push(item); } } }