...
1
2
3
4
5
6
7 package quic
8
9 import (
10 "net/netip"
11 "sync"
12 )
13
14 type datagram struct {
15 b []byte
16 addr netip.AddrPort
17 }
18
19 var datagramPool = sync.Pool{
20 New: func() any {
21 return &datagram{
22 b: make([]byte, maxUDPPayloadSize),
23 }
24 },
25 }
26
27 func newDatagram() *datagram {
28 m := datagramPool.Get().(*datagram)
29 m.b = m.b[:cap(m.b)]
30 return m
31 }
32
33 func (m *datagram) recycle() {
34 if cap(m.b) != maxUDPPayloadSize {
35 return
36 }
37 datagramPool.Put(m)
38 }
39
View as plain text