Clash.Meta/common/pool/buffer.go

18 lines
264 B
Go
Raw Normal View History

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