mirror of https://github.com/jlelse/GoBlog
24 lines
312 B
Go
24 lines
312 B
Go
|
package bufferpool
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"sync"
|
||
|
)
|
||
|
|
||
|
var bufferPool = sync.Pool{
|
||
|
New: func() interface{} {
|
||
|
return new(bytes.Buffer)
|
||
|
},
|
||
|
}
|
||
|
|
||
|
func Get() *bytes.Buffer {
|
||
|
return bufferPool.Get().(*bytes.Buffer)
|
||
|
}
|
||
|
|
||
|
func Put(bufs ...*bytes.Buffer) {
|
||
|
for _, buf := range bufs {
|
||
|
buf.Reset()
|
||
|
bufferPool.Put(buf)
|
||
|
}
|
||
|
}
|