mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 03:18:59 +00:00
27 lines
343 B
Go
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:
|
|
}
|
|
}
|