syncthing/buffers/buffers.go
2013-12-15 11:43:40 +01:00

27 lines
343 B
Go

package buffers
var buffers = make(chan []byte, 32)
func Get(size int) []byte {
var buf []byte
select {
case buf = <-buffers:
default:
}
if len(buf) < size {
return make([]byte, size)
}
return buf[:size]
}
func Put(buf []byte) {
if cap(buf) == 0 {
return
}
buf = buf[:cap(buf)]
select {
case buffers <- buf:
default:
}
}