2024-09-26 09:00:05 +00:00
|
|
|
package httputil
|
2018-06-07 07:46:03 +00:00
|
|
|
|
|
|
|
import "sync"
|
|
|
|
|
2024-09-26 09:00:05 +00:00
|
|
|
const bufferSize = 32 * 1024
|
|
|
|
|
|
|
|
type bufferPool struct {
|
|
|
|
pool sync.Pool
|
|
|
|
}
|
2018-06-07 07:46:03 +00:00
|
|
|
|
|
|
|
func newBufferPool() *bufferPool {
|
2024-09-26 09:00:05 +00:00
|
|
|
b := &bufferPool{
|
|
|
|
pool: sync.Pool{},
|
2018-06-07 07:46:03 +00:00
|
|
|
}
|
|
|
|
|
2024-09-26 09:00:05 +00:00
|
|
|
b.pool.New = func() interface{} {
|
|
|
|
return make([]byte, bufferSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
return b
|
2018-06-07 07:46:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *bufferPool) Get() []byte {
|
|
|
|
return b.pool.Get().([]byte)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *bufferPool) Put(bytes []byte) {
|
|
|
|
b.pool.Put(bytes)
|
|
|
|
}
|