summaryrefslogtreecommitdiff
path: root/internal/io/pool/bytesbuffer.go
blob: 3d48f2cdf888f4838d96ee6d078a638909bb6a0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package pool

import (
	"bytes"
	"sync"
)

// BytesBuffer is there to optimize memory allocations. DTail otherwise allocates
// a lot of memory while reading logs.
var BytesBuffer = sync.Pool{
	New: func() interface{} {
		b := bytes.Buffer{}
		b.Grow(128)
		return &b
	},
}

// RecycleBytesBuffer recycles the buffer again.
func RecycleBytesBuffer(b *bytes.Buffer) {
	b.Reset()
	BytesBuffer.Put(b)
}