bytes

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package bytes implements functions for manipulating byte slices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferPool

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

BufferPool is a pool implementation of bytes.Buffer. This allows to reuse buffers, which means less allocations. Buffers are guaranteed to live in memory, which is a key difference between sync.Pool.

func NewBufferPool

func NewBufferPool(n, max int) BufferPool

NewBufferPool creates a pool that will hold up to n buffers. Any new buffer will be created with up to max bytes.

func (*BufferPool) Add

func (bp *BufferPool) Add(buf *bytes.Buffer)

Add appends buf to the pool. Add behaves like AddWait, but if there is no more room for buffers, buf will be discarded.

func (*BufferPool) AddWait added in v0.7.0

func (bp *BufferPool) AddWait(buf *bytes.Buffer)

AddWait appends buf to the pool. If there is no room for more buffers, AddWait will wait until buf can be appended. If buf is nil or has more than bp.max bytes, it will be discarded and a new buffer will be allocated. After calling AddWait, buf must not be used anymore.

func (*BufferPool) Cap

func (bp *BufferPool) Cap() int

Cap returns the pool capacity.

func (*BufferPool) Clear

func (bp *BufferPool) Clear()

Clear discards all the buffers in the pool.

func (*BufferPool) Fill

func (bp *BufferPool) Fill()

Fill fills the pool up to its available capacity.

func (*BufferPool) Get

func (bp *BufferPool) Get() (buf *bytes.Buffer)

Get returns a buffer from the pool. If there are no buffers in the pool, a new one with bp.max bytes will be returned.

func (*BufferPool) GetWait added in v0.7.0

func (bp *BufferPool) GetWait() *bytes.Buffer

GetWait returns a buffer from the pool. If there are no buffers in the pool, this will wait until one is available.

func (*BufferPool) Len

func (bp *BufferPool) Len() int

Len returns the amount of buffers in the pool.

type Pool added in v0.7.0

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

Pool is a pool implementation of byte slices. This allows to reuse slices, which means less allocations. Slices are guaranteed to live in memory, which is a key difference between sync.Pool.

func NewPool added in v0.7.0

func NewPool(n, max int) Pool

NewPool creates a pool that will hold up to n slices. Any new slice will be created with up to max bytes.

func (*Pool) Add added in v0.7.0

func (p *Pool) Add(s []byte)

Add appends s to the pool. Add behaves like AddWait, but if there is no more room for slices, s will be discarded.

func (*Pool) AddWait added in v0.7.0

func (p *Pool) AddWait(s []byte)

AddWait appends s to the pool. If there is no room for more slices, AddWait will wait until s can be appended. If s is nil or has more than p.max bytes, it will be discarded and a new slice will be allocated. After calling AddWait, s must not be used anymore.

func (*Pool) Cap added in v0.7.0

func (p *Pool) Cap() int

Cap returns the pool capacity.

func (*Pool) Clear added in v0.7.0

func (p *Pool) Clear()

Clear discards all the slices in the pool.

func (*Pool) Fill added in v0.7.0

func (p *Pool) Fill()

Fill fills the pool up to its available capacity.

func (*Pool) Get added in v0.7.0

func (p *Pool) Get() (s []byte)

Get returns a slice from the pool. If there are no slices in the pool, a new one with a capacity of p.max bytes will be returned.

func (*Pool) GetWait added in v0.7.0

func (p *Pool) GetWait() []byte

GetWait returns a slice from the pool. If there are no slices in the pool, this will wait until one is available.

func (*Pool) Len added in v0.7.0

func (p *Pool) Len() int

Len returns the amount of slices in the pool.

Jump to

Keyboard shortcuts

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