github.com/nsqio/nsq@v1.3.0/nsqd/buffer_pool.go (about)

     1  package nsqd
     2  
     3  import (
     4  	"bytes"
     5  	"sync"
     6  )
     7  
     8  var bp sync.Pool
     9  
    10  func init() {
    11  	bp.New = func() interface{} {
    12  		return &bytes.Buffer{}
    13  	}
    14  }
    15  
    16  func bufferPoolGet() *bytes.Buffer {
    17  	return bp.Get().(*bytes.Buffer)
    18  }
    19  
    20  func bufferPoolPut(b *bytes.Buffer) {
    21  	b.Reset()
    22  	bp.Put(b)
    23  }