forked from egametang/ET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessagePool.cs
More file actions
67 lines (59 loc) · 1.55 KB
/
Copy pathMessagePool.cs
File metadata and controls
67 lines (59 loc) · 1.55 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
#if !NOT_UNITY
using System.Collections.Generic;
#endif
namespace ET
{
// 客户端为了0GC需要消息池,服务端消息需要跨协程不需要消息池
public class MessagePool
{
public static MessagePool Instance
{
get;
} = new MessagePool();
#if !NOT_UNITY
private readonly Dictionary<Type, Queue<object>> dictionary = new Dictionary<Type, Queue<object>>();
#endif
public object Fetch(Type type)
{
//Queue<object> queue;
//if (!this.dictionary.TryGetValue(type, out queue))
//{
// queue = new Queue<object>();
// this.dictionary.Add(type, queue);
//}
//
//object obj;
//if (queue.Count > 0)
//{
// obj = queue.Dequeue();
//}
//else
//{
// obj = Activator.CreateInstance(type);
//}
//return obj;
return Activator.CreateInstance(type);
}
public T Fetch<T>() where T : class
{
T t = (T) this.Fetch(typeof (T));
return t;
}
public void Recycle(object obj)
{
/*
#if !NOT_CLIENT
Type type = obj.GetType();
Queue<object> queue;
if (!this.dictionary.TryGetValue(type, out queue))
{
queue = new Queue<object>();
this.dictionary.Add(type, queue);
}
queue.Enqueue(obj);
#endif
*/
}
}
}