package buf import ( "sync" ) const ( defaultByteBufferSize = 4096 ) type ByteBufferPool struct { pool sync.Pool } func (p *ByteBufferPool) Acquire() *ByteBuffer { v := p.pool.Get() if v == nil { return &ByteBuffer{ B: make([]byte, 0, defaultByteBufferSize), } } return v.(*ByteBuffer) } func (p *ByteBufferPool) Release(b *ByteBuffer) { b.Reset() p.pool.Put(b) }