2022-12-06 10:25:19 +00:00
|
|
|
package putsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
const defaultAllocSize = 1024
|
|
|
|
|
2023-04-03 10:09:44 +00:00
|
|
|
type payload struct {
|
|
|
|
Data []byte
|
|
|
|
}
|
|
|
|
|
2022-12-06 10:25:19 +00:00
|
|
|
var putBytesPool = &sync.Pool{
|
2023-04-03 10:09:44 +00:00
|
|
|
New: func() any { return &payload{Data: make([]byte, 0, defaultAllocSize)} },
|
2022-12-06 10:25:19 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 10:09:44 +00:00
|
|
|
func getPayload() *payload {
|
|
|
|
return putBytesPool.Get().(*payload)
|
2022-12-06 10:25:19 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 10:09:44 +00:00
|
|
|
func putPayload(p *payload) {
|
|
|
|
p.Data = p.Data[:0]
|
|
|
|
putBytesPool.Put(p)
|
2022-12-06 10:25:19 +00:00
|
|
|
}
|