blob: 21871f18d4f4d954b2b7baa4b1ab66c6bc716cf8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
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{}
// Increase initial capacity to 4KB to reduce reallocations
// Most log lines are between 100-500 bytes, but some can be larger
b.Grow(4096)
return &b
},
}
// RecycleBytesBuffer recycles the buffer again.
func RecycleBytesBuffer(b *bytes.Buffer) {
b.Reset()
BytesBuffer.Put(b)
}
|