mirror of
https://github.com/pyihe/go-pkg.git
synced 2025-10-06 16:36:50 +08:00
36 lines
442 B
Go
36 lines
442 B
Go
package buffers
|
|
|
|
import (
|
|
"bytes"
|
|
"sync"
|
|
)
|
|
|
|
//type ByteBuffer = bytebufferpool.ByteBuffer
|
|
//
|
|
//var (
|
|
// Get = bytebufferpool.Get
|
|
// Put = func(b *ByteBuffer) {
|
|
// if b != nil {
|
|
// bytebufferpool.Put(b)
|
|
// }
|
|
// }
|
|
//)
|
|
|
|
var bp sync.Pool
|
|
|
|
func Get() *bytes.Buffer {
|
|
buffer, ok := bp.Get().(*bytes.Buffer)
|
|
if ok {
|
|
return buffer
|
|
}
|
|
return &bytes.Buffer{}
|
|
}
|
|
|
|
func Put(b *bytes.Buffer) {
|
|
if b == nil {
|
|
return
|
|
}
|
|
b.Reset()
|
|
bp.Put(b)
|
|
}
|