We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1ff2560 commit 53d0be4Copy full SHA for 53d0be4
ObjectPool.cs
@@ -0,0 +1,44 @@
1
+using UnityEngine;
2
+using System;
3
+using System.Collections;
4
+using System.Collections.Generic;
5
+using System.Threading;
6
+
7
8
+namespace KBEngine
9
+{
10
+ /// <summary>
11
+ /// 简单的对象池
12
+ /// </summary>
13
+ /// <typeparam name="T">对象类型</typeparam>
14
+ public class ObjectPool<T> where T : new()
15
+ {
16
+ private static LinkedList<T> _objects = new LinkedList<T>();
17
18
+ public static T getObject()
19
20
+ lock (_objects)
21
22
+ if (_objects.First != null)
23
24
+ T v = _objects.First.Value;
25
+ _objects.RemoveFirst();
26
+ return v;
27
+ }
28
+ else
29
30
+ return new T();
31
32
33
34
35
+ public static void putObject(T item)
36
37
38
39
+ _objects.AddLast(item);
40
41
42
43
44
+}
0 commit comments