buffer_pool.go 496 B

123456789101112131415161718192021222324252627
  1. package quic
  2. import (
  3. "sync"
  4. "v2ray.com/core/common/bytespool"
  5. "github.com/lucas-clemente/quic-go/internal/protocol"
  6. )
  7. var bufferPool *sync.Pool
  8. func getPacketBuffer() *[]byte {
  9. b := bufferPool.Get().([]byte)
  10. return &b
  11. }
  12. func putPacketBuffer(buf *[]byte) {
  13. if cap(*buf) < int(protocol.MaxReceivePacketSize) {
  14. panic("putPacketBuffer called with packet of wrong size!")
  15. }
  16. bufferPool.Put(*buf)
  17. }
  18. func init() {
  19. bufferPool = bytespool.GetPool(int32(protocol.MaxReceivePacketSize))
  20. }