amuz.es/src/infra/goutils@v0.1.3/buf/bytebuf_pool.go (about) 1 package buf 2 3 import ( 4 "sync" 5 ) 6 7 const ( 8 defaultByteBufferSize = 4096 9 ) 10 11 type ByteBufferPool struct { 12 pool sync.Pool 13 } 14 15 func (p *ByteBufferPool) Acquire() *ByteBuffer { 16 v := p.pool.Get() 17 if v == nil { 18 return &ByteBuffer{ 19 B: make([]byte, 0, defaultByteBufferSize), 20 } 21 } 22 return v.(*ByteBuffer) 23 } 24 25 func (p *ByteBufferPool) Release(b *ByteBuffer) { 26 b.Reset() 27 p.pool.Put(b) 28 }