github.com/metacubex/mihomo@v1.18.5/common/pool/buffer.go (about)

     1  package pool
     2  
     3  import (
     4  	"bytes"
     5  	"sync"
     6  )
     7  
     8  var bufferPool = sync.Pool{New: func() any { return &bytes.Buffer{} }}
     9  
    10  func GetBuffer() *bytes.Buffer {
    11  	return bufferPool.Get().(*bytes.Buffer)
    12  }
    13  
    14  func PutBuffer(buf *bytes.Buffer) {
    15  	buf.Reset()
    16  	bufferPool.Put(buf)
    17  }