blob: 9cdf3e4f4c4497d07364532b3a3f3ab4978b818c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
using System;
using System.Collections.Generic;
namespace XMainClient
{
public class XDataPool<T> where T : XDataBase, new()
{
private static Queue<T> _pool = new Queue<T>();
public static T GetData()
{
bool flag = XDataPool<T>._pool.Count > 0;
T result;
if (flag)
{
T t = XDataPool<T>._pool.Dequeue();
t.Init();
t.bRecycled = false;
result = t;
}
else
{
T t2 = Activator.CreateInstance<T>();
t2.Init();
t2.bRecycled = false;
result = t2;
}
return result;
}
public static void Recycle(T data)
{
bool flag = !data.bRecycled;
if (flag)
{
XDataPool<T>._pool.Enqueue(data);
data.bRecycled = true;
}
}
}
}
|