From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Assets/Scripts/XUtliPoolLib/BufferPoolMgr.cs | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Client/Assets/Scripts/XUtliPoolLib/BufferPoolMgr.cs (limited to 'Client/Assets/Scripts/XUtliPoolLib/BufferPoolMgr.cs') diff --git a/Client/Assets/Scripts/XUtliPoolLib/BufferPoolMgr.cs b/Client/Assets/Scripts/XUtliPoolLib/BufferPoolMgr.cs new file mode 100644 index 00000000..b97e7f3c --- /dev/null +++ b/Client/Assets/Scripts/XUtliPoolLib/BufferPoolMgr.cs @@ -0,0 +1,63 @@ +using System; + +namespace XUtliPoolLib +{ + public class BufferPoolMgr : XSingleton + { + private SmallBufferPool m_UIntSmallBufferPool = new SmallBufferPool(); + + private SmallBufferPool m_ObjSmallBufferPool = new SmallBufferPool(); + + 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 sb, int size, int initSize = 0) + { + this.m_UIntSmallBufferPool.GetBlock(ref sb, size, 0); + } + + public void ReturnSmallBuffer(ref SmallBuffer sb) + { + this.m_UIntSmallBufferPool.ReturnBlock(ref sb); + } + + public void GetSmallBuffer(ref SmallBuffer sb, int size, int initSize = 0) + { + this.m_ObjSmallBufferPool.GetBlock(ref sb, size, 0); + } + + public void ReturnSmallBuffer(ref SmallBuffer sb) + { + this.m_ObjSmallBufferPool.ReturnBlock(ref sb); + } + } +} -- cgit v1.1-26-g67d0