Documentation ¶
Overview ¶
Package buffer implements a pool of pointers to byte slices.
Example usage pattern
p := buffer.Get(size) b := *p // Now you can use b in any way you need. ... // When b will not be used anymore buffer.Put(p) ... // If b or p are not going out of scope soon, optionally b = nil p = nil
Otherwise the pool cannot release the buffer on garbage collection.
Do not do
p := buffer.Get(size) b := *p ... buffer.Put(&b)
or
b := *buffer.Get(size) ... buffer.Put(&b)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CGet ¶
CGet returns a pointer to a byte slice of len size. The pointed to byte slice is zeroed up to its cap. CGet panics for size < 0.
CGet is safe for concurrent use by multiple goroutines.
Types ¶
type Bytes ¶
type Bytes struct {
// contains filtered or unexported fields
}
Bytes is similar to bytes.Buffer but may generate less garbage when properly Closed. Zero value is ready to use.
func (*Bytes) Close ¶
Close will recycle the underlying storage, if any. After Close, b is again the zero value.
func (*Bytes) Reset ¶
func (b *Bytes) Reset()
Reset discard the content of Bytes while keeping the internal storage, if any.
func (*Bytes) WriteString ¶
WriteString writes s to b and returns (len(s), nil).