This repository has been archived on 2022-07-30. You can view files and clone it, but cannot push or open issues/pull-requests.
mdb/kvstore/globals.go

33 lines
487 B
Go
Raw Permalink Normal View History

2022-07-29 19:36:42 +00:00
package kvstore
2022-07-30 03:58:35 +00:00
import (
2022-07-30 07:20:54 +00:00
"sync"
2022-07-30 03:58:35 +00:00
"time"
)
2022-07-29 19:36:42 +00:00
var (
2022-07-30 03:58:35 +00:00
connTimeout = 16 * time.Second
pollInterval = 500 * time.Millisecond
modQSize = 1024
2022-07-30 07:20:54 +00:00
poolBufSize = 8192
bufferPool = sync.Pool{
New: func() any {
return make([]byte, poolBufSize)
},
}
2022-07-29 19:36:42 +00:00
)
2022-07-30 03:58:35 +00:00
func GetDataBuf(size int) []byte {
if size > poolBufSize {
return make([]byte, size)
}
2022-07-30 07:20:54 +00:00
return bufferPool.Get().([]byte)[:size]
2022-07-30 03:58:35 +00:00
}
func RecycleDataBuf(b []byte) {
if cap(b) != poolBufSize {
return
}
2022-07-30 07:20:54 +00:00
bufferPool.Put(b)
2022-07-30 03:58:35 +00:00
}