Documentation ¶
Overview ¶
Package bytesbuffers provides multiple implementations of a "byte buffer pool" allowing for reuse of preallocated memory in the form of a *bytes.Buffer.
Example Usage: Marshal a JSON request body to a buffer, then put it back in the pool after the request.
pool := bytesbuffers.NewSyncPool(4) var obj MyInput{} buffer := pool.Get() defer pool.Put(buffer) _ = json.NewEncoder(buffer).Encode(obj) _, _ = http.Post("http://localhost:1234", "application/json", buffer)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool interface { // Get reset bytes buffer from the pool. Get() *bytes.Buffer // Put adds buf to the pool. Put(buf *bytes.Buffer) }
Pool is a type-safe interface for a pool of bytes buffers.
func NewSizedPool ¶
NewSizedPool stores (up to) a fixed size of released bytes buffers in the pool.
Stored bytes buffers are not garbage collected until the reference to the pool is lost.
Use this for steady high-volume workloads.
func NewSyncPool ¶
NewSyncPool uses the standard library's sync.Pool to store reusable bytes buffers until the next GC.
This self-sizes based on the highest concurrent usage per GC period.
Use this for spiky workloads.