Source File
bufpool.go
Belonging Package
github.com/tmc/go-iroh/internal/relayproto
package relayprotoimportvar (smallPool = sync.Pool{New: func() any { := make([]byte, 2048); return & }}largePool = sync.Pool{New: func() any { := make([]byte, MaxPacketSize); return & }})// GetBuf returns a buffer of length n. A frame may encode to more than// MaxPacketSize, which no pool here holds, so n above that is allocated.func ( int) *[]byte {var *[]byteswitch {case <= 2048:= smallPool.Get().(*[]byte)case <= MaxPacketSize:= largePool.Get().(*[]byte)default::= make([]byte, )return &}* = (*)[:]return}// PutBuf returns a buffer obtained from GetBuf. A buffer larger than either// pool holds is dropped rather than kept.func ( *[]byte) {switch := cap(*); {case <= 2048:smallPool.Put()case <= MaxPacketSize:largePool.Put()}}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |