clash/common/pool/buffer.go

18 lines
272 B
Go
Raw Normal View History

2021-09-20 13:02:18 +00:00
package pool
import (
"bytes"
"sync"
)
var bufferPool = sync.Pool{New: func() interface{} { return &bytes.Buffer{} }}
func GetBuffer() *bytes.Buffer {
return bufferPool.Get().(*bytes.Buffer)
}
func PutBuffer(buf *bytes.Buffer) {
buf.Reset()
bufferPool.Put(buf)
}