diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2021-10-21 21:28:49 +0300 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2021-10-21 21:28:49 +0300 |
| commit | 23a51718d029677ba9076617b1213e87c0e1bf98 (patch) | |
| tree | ea5e4a2d2a67035f645bdee496ae55a52034178a /internal/io/pool/bytesbuffer.go | |
| parent | 68c588f50eb57f40c137a9645af18498b01580d0 (diff) | |
| parent | a1ee5e7700f22c5a9b0a6654291eb46bdf4e6272 (diff) | |
merge develop
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) +} |
