1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-14 07:58:16 -04:00
v2fly/vendor/github.com/lucas-clemente/quic-go/buffer_pool.go

29 lines
428 B
Go
Raw Normal View History

2018-11-20 17:51:25 -05:00
package quic
import (
"sync"
2018-11-21 04:49:41 -05:00
"v2ray.com/core/common/bytespool"
2018-11-20 17:51:25 -05:00
"github.com/lucas-clemente/quic-go/internal/protocol"
)
2018-11-21 04:49:41 -05:00
var bufferPool *sync.Pool
2018-11-20 17:51:25 -05:00
func getPacketBuffer() *[]byte {
2018-11-21 04:49:41 -05:00
b := bufferPool.Get().([]byte)
return &b
2018-11-20 17:51:25 -05:00
}
func putPacketBuffer(buf *[]byte) {
2018-11-21 05:03:47 -05:00
b := *buf
if cap(b) < 2048 {
return
2018-11-20 17:51:25 -05:00
}
2018-11-21 05:03:47 -05:00
bufferPool.Put(b[:cap(b)])
2018-11-20 17:51:25 -05:00
}
func init() {
2018-11-21 04:52:07 -05:00
bufferPool = bytespool.GetPool(int32(protocol.MaxReceivePacketSize))
2018-11-20 17:51:25 -05:00
}