Skip to content

Commit

Permalink
Merge pull request #15 from TraditoreZ/master
Browse files Browse the repository at this point in the history
优化对象池结构
  • Loading branch information
kbengine authored Sep 22, 2017
2 parents 10d4f0b + 2883f9c commit b6f3e67
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ namespace KBEngine
/// <typeparam name="T">对象类型</typeparam>
public class ObjectPool<T> where T : new()
{
private static LinkedList<T> _objects = new LinkedList<T>();

private static Stack<T> _objects = new Stack<T>();
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
Expand All @@ -36,7 +36,7 @@ public static void reclaimObject(T item)
{
lock (_objects)
{
_objects.AddLast(item);
_objects.Push(item);
}
}
}
Expand Down

0 comments on commit b6f3e67

Please sign in to comment.