bufferpool

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Put

func Put(b *Buffer)

Put returns byte buffer to the pool.

Buffer.B mustn't be touched after returning it to the pool. Otherwise data races will occur.

func ReleaseByteBuffer

func ReleaseByteBuffer(bb *Buffer)

Types

type Buffer

type Buffer struct {
	Buf []byte
}

func AcquireByteBuffer

func AcquireByteBuffer() *Buffer

func Get

func Get() *Buffer

Get returns an empty byte buffer from the pool.

Got byte buffer may be returned to the pool via Put call. This reduces the number of memory allocations required for byte buffer management.

func (*Buffer) Bytes

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

Bytes returns b.Buf, i.e. all the bytes accumulated in the buffer.

The purpose of this function is bytes.Buffer compatibility.

func (*Buffer) Expand

func (b *Buffer) Expand(l, c int)

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the size of the byte buffer.

func (*Buffer) ReadFrom

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

ReadFrom implements io.ReaderFrom.

The function appends all the data read from r to b.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset makes Buffer.B empty.

func (*Buffer) Set

func (b *Buffer) Set(p []byte)

Set sets Buffer.B to p.

func (*Buffer) SetString

func (b *Buffer) SetString(s string)

SetString sets Buffer.B to s.

func (*Buffer) String

func (b *Buffer) String() string

String returns string representation of Buffer.B.

func (*Buffer) Write

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

Write implements io.Writer - it appends p to Buffer.B

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(c byte) error

WriteByte appends the byte c to the buffer.

The purpose of this function is bytes.Buffer compatibility.

The function always returns nil.

func (*Buffer) WriteString

func (b *Buffer) WriteString(s string) (int, error)

WriteString appends s to Buffer.B.

func (*Buffer) WriteTo

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

WriteTo implements io.WriterTo.

type Pool

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

Pool represents byte buffer pool.

Distinct pools may be used for distinct types of byte buffers. Properly determined byte buffer types with their own pools may help reducing memory waste.

func (*Pool) Get

func (p *Pool) Get() *Buffer

Get returns new byte buffer with zero length.

The byte buffer may be returned to the pool via Put after the use in order to minimize GC overhead.

func (*Pool) Put

func (p *Pool) Put(b *Buffer)

Put releases byte buffer obtained via GetHeader to the pool.

The buffer mustn't be accessed after returning to the pool.

Jump to

Keyboard shortcuts

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