bufferpool

package
v0.0.0-...-678bb0e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2017 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package bufferpool implements a pool of bytes.Buffer instances backed by a sync.Pool. The goal of using a buffer pool is that, in exchange for some locking overhead, the user can avoid iteratively reallocating buffers for frequently used purposes.

Ideal usage of bufferpool is with like-purposed buffers in order to encourage the pool to contain buffers sized to that specific purpose. If this is correctly implemented, the buffers in the pool should generally come into existence, grow to the purpose's size need, and then remain there without further allocation.

An overly-broad-purposed pool, on the other hand, will have its buffers grow to max(purpose...) size and consequently contain more large buffers than necessary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	*bytes.Buffer
	// contains filtered or unexported fields
}

Buffer is a bytes.Buffer that is bound to a pool. It should not be used directly, but rather obtained through calling Get on a P instance.

func (*Buffer) Clone

func (b *Buffer) Clone() []byte

Clone clones the contents of the buffer's Bytes, returning an indepdent duplicate []byte.

func (*Buffer) Release

func (b *Buffer) Release()

Release returns this Buffer to its pool.

After calling Release, no accesses may be made to b or its internal data. If its data is to be retained, it must be cloned prior to Release (see Clone).

type P

type P struct {
	// contains filtered or unexported fields
}

P is a pool of buffers. The zero value is an initialized but empty pool.

P must be passed around as reference, not value.

func (*P) Get

func (p *P) Get() *Buffer

Get returns a Buffer. When the caller is finished with the Buffer, they should call Release to return it to its pool.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL