bufferpool

package
v1.27.2 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2018 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bufferpool maintains a pool of bytes.Buffers for use in encoding and transport implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Put

func Put(buf *Buffer)

Put returns a Buffer to the Buffer pool.

Types

type Buffer added in v1.27.0

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

Buffer represents a poolable buffer. It wraps an underlying *bytes.Buffer with lightweight detection of races.

func Get

func Get() *Buffer

Get returns a new Buffer from the Buffer pool that has been reset.

func (*Buffer) Bytes added in v1.27.0

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

Bytes returns the bytes in the underlying buffer, as well as a function to call when the caller is done using the bytes. This is easy to mis-use and lead to a use-after-free that cannot be detected, so it is strongly recommended that this method is NOT used.

func (*Buffer) Len added in v1.27.0

func (b *Buffer) Len() int

Len is the same as bytes.Buffer.Len.

func (*Buffer) Read added in v1.27.0

func (b *Buffer) Read(p []byte) (int, error)

Read is the same as bytes.Buffer.Read.

func (*Buffer) ReadFrom added in v1.27.0

func (b *Buffer) ReadFrom(r io.Reader) (int64, error)

ReadFrom is the same as bytes.Buffer.ReadFrom.

func (*Buffer) Release added in v1.27.0

func (b *Buffer) Release()

Release releases the buffer back to the buffer pool.

func (*Buffer) Reset added in v1.27.0

func (b *Buffer) Reset()

Reset is the same as bytes.Buffer.Reset.

func (*Buffer) Write added in v1.27.0

func (b *Buffer) Write(p []byte) (int, error)

Write is the same as bytes.Buffer.Write.

func (*Buffer) WriteTo added in v1.27.0

func (b *Buffer) WriteTo(w io.Writer) (int64, error)

WriteTo is the same as bytes.Buffer.WriteTo.

type Option added in v1.27.0

type Option func(*Pool)

Option configures a buffer pool.

func DetectUseAfterFreeForTests added in v1.27.0

func DetectUseAfterFreeForTests() Option

DetectUseAfterFreeForTests is an option that allows unit tests to detect bad use of a pooled buffer after it has been released to the pool.

type Pool added in v1.27.0

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

Pool represents a buffer pool with a set of options.

func NewPool added in v1.27.0

func NewPool(opts ...Option) *Pool

NewPool returns a pool that we can allocate buffers from.

func (*Pool) Get added in v1.27.0

func (p *Pool) Get() *Buffer

Get returns a buffer from the pool.

Jump to

Keyboard shortcuts

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