summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XUtliPoolLib/BufferPoolMgr.cs
blob: b97e7f3c1e7dc4423179815d3ce2862265ee8667 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;

namespace XUtliPoolLib
{
	public class BufferPoolMgr : XSingleton<BufferPoolMgr>
	{
		private SmallBufferPool<uint> m_UIntSmallBufferPool = new SmallBufferPool<uint>();

		private SmallBufferPool<object> m_ObjSmallBufferPool = new SmallBufferPool<object>();

		public static int TotalCount = 0;

		public static int AllocSize = 0;

		public BlockInfo[] uintBlockInit = new BlockInfo[]
		{
			new BlockInfo(4, 512),
			new BlockInfo(8, 512),
			new BlockInfo(16, 512),
			new BlockInfo(32, 512),
			new BlockInfo(64, 512),
			new BlockInfo(256, 128),
			new BlockInfo(512, 128)
		};

		public BlockInfo[] objBlockInit = new BlockInfo[]
		{
			new BlockInfo(8, 512),
			new BlockInfo(16, 512),
			new BlockInfo(32, 512),
			new BlockInfo(64, 512),
			new BlockInfo(256, 128),
			new BlockInfo(512, 128)
		};

		public override bool Init()
		{
			this.m_UIntSmallBufferPool.Init(this.uintBlockInit, 4);
			this.m_ObjSmallBufferPool.Init(this.objBlockInit, 4);
			return true;
		}

		public void GetSmallBuffer(ref SmallBuffer<uint> sb, int size, int initSize = 0)
		{
			this.m_UIntSmallBufferPool.GetBlock(ref sb, size, 0);
		}

		public void ReturnSmallBuffer(ref SmallBuffer<uint> sb)
		{
			this.m_UIntSmallBufferPool.ReturnBlock(ref sb);
		}

		public void GetSmallBuffer(ref SmallBuffer<object> sb, int size, int initSize = 0)
		{
			this.m_ObjSmallBufferPool.GetBlock(ref sb, size, 0);
		}

		public void ReturnSmallBuffer(ref SmallBuffer<object> sb)
		{
			this.m_ObjSmallBufferPool.ReturnBlock(ref sb);
		}
	}
}