buffer

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: MIT Imports: 8 Imported by: 5

Documentation

Overview

Example (Index)
for _, i := range [...]int{64, 128, 192, 256, 257} {
	fmt.Println(i, "=", index(i))
}
Output:


64 = 0
128 = 1
192 = 2
256 = 2
257 = 3
Example (RoundPow)
for _, i := range [...]int{0, 1, 2, 64, 128, 192, 256, 257} {
	fmt.Println(i, "=", roundPow(i))
}
Output:


0 = 1
1 = 1
2 = 2
64 = 64
128 = 128
192 = 256
256 = 256
257 = 512

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNegativeCount = errors.New("negative count")
)

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	B []byte
}

A byte buffer, highly optimized to minimize allocations and GC pressure.

func NewBuffer

func NewBuffer(size int) *Buffer

func (*Buffer) Bytes

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

func (*Buffer) Cap

func (b *Buffer) Cap() int

func (*Buffer) Grow

func (b *Buffer) Grow(n int) error

Grow grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, Grow panics.

func (*Buffer) Len

func (b *Buffer) Len() int

func (*Buffer) ReadFrom

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

ReadFrom implements io.ReaderFrom.

func (*Buffer) Reset

func (b *Buffer) Reset()

func (*Buffer) String

func (b *Buffer) String() string

WriteString implements fmt.Stringer.

func (*Buffer) Write

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

Write implements io.Writer.

func (*Buffer) WriteByte

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

WriteByte implements io.ByteWriter.

func (*Buffer) WriteString

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

WriteString implements io.StringWriter.

func (*Buffer) WriteTo

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

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 Get 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