seaweedfs/weed/operation/buffer_pool.go

25 lines
445 B
Go
Raw Normal View History

2021-04-01 09:20:00 +00:00
package operation
import (
"github.com/valyala/bytebufferpool"
"sync/atomic"
)
var bufferCounter int64
2021-04-02 09:22:59 +00:00
2021-04-01 09:20:00 +00:00
func GetBuffer() *bytebufferpool.ByteBuffer {
defer func() {
atomic.AddInt64(&bufferCounter, 1)
// println("+", bufferCounter)
}()
return bytebufferpool.Get()
}
func PutBuffer(buf *bytebufferpool.ByteBuffer) {
defer func() {
atomic.AddInt64(&bufferCounter, -1)
// println("-", bufferCounter)
}()
bytebufferpool.Put(buf)
}