syncthing/buffers/buffers.go

27 lines
343 B
Go
Raw Normal View History

2013-12-15 10:43:31 +00:00
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:
}
}