This commit is contained in:
Jakob Borg
2013-12-15 11:43:31 +01:00
commit bfe935b5ab
26 changed files with 2866 additions and 0 deletions

26
buffers/buffers.go Normal file
View File

@@ -0,0 +1,26 @@
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:
}
}