We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 10d4f0b commit 2883f9cCopy full SHA for 2883f9c
ObjectPool.cs
@@ -13,16 +13,16 @@ namespace KBEngine
13
/// <typeparam name="T">对象类型</typeparam>
14
public class ObjectPool<T> where T : new()
15
{
16
- private static LinkedList<T> _objects = new LinkedList<T>();
17
-
+ private static Stack<T> _objects = new Stack<T>();
+ private static T v;
18
+
19
public static T createObject()
20
21
lock (_objects)
22
- if (_objects.First != null)
23
+ if (_objects.Count > 0)
24
- T v = _objects.First.Value;
25
- _objects.RemoveFirst();
+ v = _objects.Pop();
26
return v;
27
}
28
else
@@ -36,7 +36,7 @@ public static void reclaimObject(T item)
36
37
38
39
- _objects.AddLast(item);
+ _objects.Push(item);
40
41
42
0 commit comments