# README
go-buffer-pool
A variable size buffer pool for go.
Table of Contents
Use Case
Use this when you need to repeatedly allocate and free a bunch of temporary buffers of approximately the same size.
Advantages over GC
-
Reduces Memory Usage:
- We don't have to wait for a GC to run before we can reuse memory. This is essential if you're repeatedly allocating large short-lived buffers.
-
Reduces CPU usage:
- It takes some load off of the GC (due to buffer reuse).
- We don't have to zero buffers (fewer wasteful memory writes).
Disadvantages over GC:
- Can leak memory contents. Unlike the go GC, we don't zero memory.
- All buffers have a capacity of a power of 2. This is fine if you either (a) actually need buffers with this size or (b) expect these buffers to be temporary.
- Requires that buffers be returned explicitly. This can lead to race conditions and memory corruption if the buffer is released while it's still in use.
Contribute
PRs are welcome!
Small note: If editing the Readme, please conform to the standard-readme specification.
License
MIT © Protocol Labs BSD © The Go Authors
The last gx published version of this module was: 0.1.3: QmQDvJoB6aJWN3sjr3xsgXqKCXf4jU5zdMXpDMsBkYVNqa
# Functions
Get retrieves a buffer of the appropriate length from the global buffer pool (or allocates a new one).
NewBuffer constructs a new buffer initialized to `buf`.
NewBufferString is identical to NewBuffer *except* that it allows one to initialize the buffer from a string (without having to allocate an intermediate bytes slice).
Put returns a buffer to the global buffer pool.
# Constants
MaxLength is the maximum length of an element that can be added to the Pool.
MinRead is the minimum slice size passed to a Read call by Buffer.ReadFrom.
No description provided by the author
# Variables
GlobalPool is a static Pool for reusing byteslices of various sizes.
# Structs
Buffer is a buffer like bytes.Buffer that:
1.
BufferPool is a pool to handle cases of reusing elements of varying sizes.
Writer is a buffered writer that returns its internal buffer in a pool when not in use.