/// <summary> /// Add a TCPOutPacket instance to the pool. /// </summary> /// <param name="item">SocketAsyncEventArgs instance to add to the pool.</param> internal void Push(TCPOutPacket item) { if (item == null) { throw new ArgumentNullException("添加到TCPOutPacketPool 的item不能是空(null)"); } lock (this.pool) { bool found = false; foreach (var oldItem in this.pool) { if (oldItem == item) { found = true; break; } } //必须在这儿调用,保证分配的内存被还回缓冲区 item.Reset(); if (this.pool.Count < 5000) //限制最大1000个缓存 { this.pool.Push(item); } else { item.Dispose(); //释放 } } //必须在这儿调用,保证分配的内存被还回缓冲区 // item.Reset(); // item.Dispose(); //释放 }
internal void Push(TCPOutPacket item) { if (item == null) { throw new ArgumentNullException("添加到TCPOutPacketPool 的item不能是空(null)"); } item.Reset(); item.Dispose(); }
/// <summary> /// Add a TCPOutPacket instance to the pool. /// </summary> /// <param name="item">SocketAsyncEventArgs instance to add to the pool.</param> internal void Push(TCPOutPacket item) { if (item == null) { throw new ArgumentNullException("添加到TCPOutPacketPool 的item不能是空(null)"); } lock (this.pool) { item.Reset(); this.pool.Push(item); } }