You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
360 B
25 lines
360 B
3 years ago
|
package bpool
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"sync"
|
||
|
)
|
||
|
|
||
|
var bpool sync.Pool
|
||
|
|
||
|
// Get returns a buffer from the pool or creates a new one if
|
||
|
// the pool is empty.
|
||
|
func Get() *bytes.Buffer {
|
||
|
b := bpool.Get()
|
||
|
if b == nil {
|
||
|
return &bytes.Buffer{}
|
||
|
}
|
||
|
return b.(*bytes.Buffer)
|
||
|
}
|
||
|
|
||
|
// Put returns a buffer into the pool.
|
||
|
func Put(b *bytes.Buffer) {
|
||
|
b.Reset()
|
||
|
bpool.Put(b)
|
||
|
}
|