using System.Collections.Generic; using DotNetty.Common; namespace dotNetty_kcp { public class CodecOutputList:List { const int DefaultInitialCapacity =16; static readonly ThreadLocalPool> Pool = new ThreadLocalPool>(handle => new CodecOutputList(handle)); readonly ThreadLocalPool.Handle returnHandle; CodecOutputList(ThreadLocalPool.Handle returnHandle) { this.returnHandle = returnHandle; } public static CodecOutputList NewInstance() => NewInstance(DefaultInitialCapacity); public static CodecOutputList NewInstance(int minCapacity) { CodecOutputList ret = Pool.Take(); if (ret.Capacity < minCapacity) { ret.Capacity = minCapacity; } return ret; } public void Return() { this.Clear(); this.returnHandle.Release(this); } } }