Files
tsnet-proxy/netforward/buffer.go
2023-11-29 15:41:06 +00:00

28 lines
426 B
Go

// From https://github.com/goburrow/netforward
package netforward
import "sync"
const (
bufferSize = 32 * 1024
)
var (
bufferPool = sync.Pool{
New: func() interface{} {
return make([]byte, bufferSize)
},
}
)
func getBuffer() []byte {
return bufferPool.Get().([]byte)
}
func releaseBuffer(b []byte) {
if len(b) != bufferSize {
panic("attempted to release buffer with invalid length")
}
bufferPool.Put(b)
}