Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool struct {
// BufSizeInit is the initial byte size of newly created new buffers. When omitted, new
// buffers have the default size of a newly created empty `bytes.Buffer` instance.
BufSizeInit int
// BufSizeMax is the maximum capacity of buffers allowed to be returned to the pool. Buffers
// whose capacity is larger than this value will be released to GC.
BufSizeMax int
// PoolSizeMax is the maximum number of buffers the pool will hold onto. Additional buffers
// returned to the pool will be released to GC.
PoolSizeMax int
// contains filtered or unexported fields
}
Pool is a free-list of
p := &gobp.Pool{
BufSizeInit: bufSize,
PoolSizeMax: poolSize,
}
// optionally, pre-initialize buffers
for i := 0; i < poolSize; i++ {
p.Put(newBuf())
}
buf := p.Get()
buf.Reset()
p.Put(buf)
func (*Pool) Get ¶
Get acquires and returns an item from the pool. Get does not block waiting for a buffer; if the pool is empty a new buffer will be created and returned.
func (*Pool) Put ¶
Put will release a buffer back to the pool. If BufSizeMax is greater than 0 and the buffer's capacity is greater than BufSizeMax, then the buffer is released to runtime GC. If PoolSizeMax is greater than 0 and there are already PoolSizeMax elements in the pool, then the buffer is released to runtime GC. Put will not block; if the pool is full the returned buffer will be immediately released to runtime GC.
Click to show internal directories.
Click to hide internal directories.