github.com/rbisecke/kafka-go@v0.4.27/buffer.go (about)

     1  package kafka
     2  
     3  import (
     4  	"bytes"
     5  	"sync"
     6  )
     7  
     8  var bufferPool = sync.Pool{
     9  	New: func() interface{} { return newBuffer() },
    10  }
    11  
    12  func newBuffer() *bytes.Buffer {
    13  	b := new(bytes.Buffer)
    14  	b.Grow(65536)
    15  	return b
    16  }
    17  
    18  func acquireBuffer() *bytes.Buffer {
    19  	return bufferPool.Get().(*bytes.Buffer)
    20  }
    21  
    22  func releaseBuffer(b *bytes.Buffer) {
    23  	if b != nil {
    24  		b.Reset()
    25  		bufferPool.Put(b)
    26  	}
    27  }