diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2022-02-04 21:37:29 +0000 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2022-02-04 21:37:29 +0000 |
| commit | 1db3b5dc1219e34e0e1c612e6646327701c40274 (patch) | |
| tree | cab22128af9e54131facd0062a474459383a1c90 /internal/io/pool/bytesbuffer.go | |
| parent | 6625d019271d3d7931587167845d77834d187d57 (diff) | |
| parent | cc6f19f69d0fb34af96e17147b2030c352d46845 (diff) | |
merge 4.0.0-RC
Diffstat (limited to 'internal/io/pool/bytesbuffer.go')
| -rw-r--r-- | internal/io/pool/bytesbuffer.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/internal/io/pool/bytesbuffer.go b/internal/io/pool/bytesbuffer.go new file mode 100644 index 0000000..3d48f2c --- /dev/null +++ b/internal/io/pool/bytesbuffer.go @@ -0,0 +1,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) +} |
