41 lines
677 B
Go
41 lines
677 B
Go
package kvstore
|
|
|
|
/*
|
|
Copyright (c) 2022, John David Lee
|
|
All rights reserved.
|
|
|
|
This source code is licensed under the BSD-style license found in the
|
|
LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
connTimeout = 16 * time.Second
|
|
pollInterval = 500 * time.Millisecond
|
|
modQSize = 1024
|
|
poolBufSize = 8192
|
|
bufferPool = sync.Pool{
|
|
New: func() any {
|
|
return make([]byte, poolBufSize)
|
|
},
|
|
}
|
|
)
|
|
|
|
func GetDataBuf(size int) []byte {
|
|
if size > poolBufSize {
|
|
return make([]byte, size)
|
|
}
|
|
return bufferPool.Get().([]byte)[:size]
|
|
}
|
|
|
|
func RecycleDataBuf(b []byte) {
|
|
if cap(b) != poolBufSize {
|
|
return
|
|
}
|
|
bufferPool.Put(b)
|
|
}
|