package utl import ( "sync" ) var ( DefBufPool *BufPool ) func init() { DefBufPool = NewBufPool(uint32(1024 * 4)) } type BufPool struct { p *sync.Pool size uint32 } func NewBufPool(size uint32) *BufPool { return &BufPool{ p: &sync.Pool{ New: func() interface{} { return make([]byte, size) }, }, size: size, } } func (self *BufPool) Get() []byte { return self.p.Get().([]byte) } func (self *BufPool) GetSize() uint32 { return self.size } func (self *BufPool) Put(data []byte) { self.p.Put(data) }