buffer_pool.go 489 B

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