forked from TrueCloudLab/certificates
internal/buffer: initial implementation of the package
This commit is contained in:
parent
e82b21c1cb
commit
2fd84227f0
1 changed files with 23 additions and 0 deletions
23
internal/buffer/buffer.go
Normal file
23
internal/buffer/buffer.go
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
// Package buffer implements a reusable buffer pool.
|
||||||
|
package buffer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Get() *bytes.Buffer {
|
||||||
|
return pool.Get().(*bytes.Buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Put(b *bytes.Buffer) {
|
||||||
|
b.Reset()
|
||||||
|
|
||||||
|
pool.Put(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
var pool = sync.Pool{
|
||||||
|
New: func() interface{} {
|
||||||
|
return new(bytes.Buffer)
|
||||||
|
},
|
||||||
|
}
|
Loading…
Reference in a new issue