using System.Collections.Generic; namespace NoSugarNet.ClientCoreNet.Standard2 { public class IdxWithMsg { public byte Idx; public byte[] data; } public class LocalMsgQueuePool { Queue msg_pool; public LocalMsgQueuePool(int capacity) { msg_pool = new Queue(capacity); } /// /// 向 Queue 的末尾添加一个对象。 /// /// public void Enqueue(IdxWithMsg item) { lock (msg_pool) { item.Idx = 0; item.data = null; msg_pool.Enqueue(item); } } //移除并返回在 Queue 的开头的对象。 public IdxWithMsg Dequeue() { lock (msg_pool) { if(msg_pool.Count > 0) return msg_pool.Dequeue(); return new IdxWithMsg(); } } public int Count { get { return msg_pool.Count; } } public void Clear() { msg_pool.Clear(); } } }