forked from quic-go/quic-go
add a sync.Pool of byte buffers with maximum packet size as cap
ref #217
This commit is contained in:
23
buffer_pool.go
Normal file
23
buffer_pool.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package quic
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
)
|
||||
|
||||
var bufferPool sync.Pool
|
||||
|
||||
func getPacketBuffer() []byte {
|
||||
return bufferPool.Get().([]byte)
|
||||
}
|
||||
|
||||
func putPacketBuffer(buf []byte) {
|
||||
bufferPool.Put(buf[:0])
|
||||
}
|
||||
|
||||
func init() {
|
||||
bufferPool.New = func() interface{} {
|
||||
return make([]byte, 0, protocol.MaxPacketSize)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user