influxdb/tsdb/engine/tsm1/pools.go

28 lines
451 B
Go
Raw Normal View History

2015-11-24 16:44:37 +00:00
package tsm1
import "sync"
var bufPool sync.Pool
2015-11-24 16:44:37 +00:00
// getBuf returns a buffer with length size from the buffer pool.
func getBuf(size int) *[]byte {
x := bufPool.Get()
if x == nil {
b := make([]byte, size)
return &b
}
buf := x.(*[]byte)
if cap(*buf) < size {
bufPool.Put(x)
b := make([]byte, size)
return &b
}
*buf = (*buf)[:size]
return buf
2015-11-24 16:44:37 +00:00
}
// putBuf returns a buffer to the pool.
func putBuf(buf *[]byte) {
2015-11-24 16:44:37 +00:00
bufPool.Put(buf)
}