package pool import ( "sync" ) const PoolSize = 64 * 1024 const PoolSizeSmall = 100 const PoolSizeUdp = 1472 const PoolSizeCopy = 32 * 1024 var BufPool = sync.Pool{ New: func() interface{} { return make([]byte, PoolSize) }, } var BufPoolUdp = sync.Pool{ New: func() interface{} { return make([]byte, PoolSizeUdp) }, } var BufPoolMax = sync.Pool{ New: func() interface{} { return make([]byte, PoolSize) }, } var BufPoolSmall = sync.Pool{ New: func() interface{} { return make([]byte, PoolSizeSmall) }, } var BufPoolCopy = sync.Pool{ New: func() interface{} { return make([]byte, PoolSizeCopy) }, } func PutBufPoolCopy(buf []byte) { if cap(buf) == PoolSizeCopy { BufPoolCopy.Put(buf[:PoolSizeCopy]) } } func PutBufPoolUdp(buf []byte) { if cap(buf) == PoolSizeUdp { BufPoolUdp.Put(buf[:PoolSizeUdp]) } }