buffer_pool.go 445 B

123456789101112131415161718192021222324
  1. package operation
  2. import (
  3. "github.com/valyala/bytebufferpool"
  4. "sync/atomic"
  5. )
  6. var bufferCounter int64
  7. func GetBuffer() *bytebufferpool.ByteBuffer {
  8. defer func() {
  9. atomic.AddInt64(&bufferCounter, 1)
  10. // println("+", bufferCounter)
  11. }()
  12. return bytebufferpool.Get()
  13. }
  14. func PutBuffer(buf *bytebufferpool.ByteBuffer) {
  15. defer func() {
  16. atomic.AddInt64(&bufferCounter, -1)
  17. // println("-", bufferCounter)
  18. }()
  19. bytebufferpool.Put(buf)
  20. }