Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AcquireWriter ¶
AcquireWriter returns an empty Writer instance from writer pool.
func ReleaseBuffer ¶
func ReleaseBuffer(buf *Buffer)
ReleaseBuffer returns buf acquired via AcquireBuffer/AcquireBufferSize to buffer pool.
It is forbidden accessing buf and/or its' members after returning it to buffer pool.
func ReleaseWriter ¶
ReleaseWriter returns buf acquired via AcquireWriter to writer pool. It will flush and reset the writer before putting to writer pool.
Types ¶
type Buffer ¶
Buffer provides byte buffer, which can be used for minimizing memory allocations and implements interfaces: io.ReaderFrom, io.WriterTo, io.ReadWriteCloser.
The allocatedSize is the buffer's initial size.
func AcquireBuffer ¶
func AcquireBuffer() *Buffer
AcquireBuffer returns an empty Buffer instance from buffer pool.
The returned Buffer instance may be passed to ReleaseBuffer when it is no longer needed. This allows Buffer recycling, reduces GC pressure and usually improves performance.
func AcquireBufferSize ¶
AcquireBufferSize returns an empty Buffer instance from buffer pool, whose capacity is greater than or equal to the giving size.
The returned Buffer instance may be passed to ReleaseBuffer when it is no longer needed. This allows Buffer recycling, reduces GC pressure and usually improves performance.
This function is recommended when you know how much memory you need actually.
func NewBufferString ¶
NewBufferString creates and initializes a new Buffer using string s as its content.
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool stores several intervals of buffer's initial capacity, which can minimizing the allocation times by bytes.Buffer.grow(n int).
It groups the scenarios of using buffer, tries to avoid a large buffer not being recycling because it's used by callers which only need a small one.
func NewBufferPool ¶
func NewBufferPool(count, base int) *BufferPool
func (*BufferPool) Get ¶
func (bp *BufferPool) Get(size int) *Buffer
Get returns a buffer with a capacity from the buffer pool.
func (*BufferPool) Put ¶
func (bp *BufferPool) Put(buf *Buffer)
Put puts the buf to the buffer pool.