bytebufferpool

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: MIT, MIT Imports: 4 Imported by: 1

README

bytebufferpool

Port of github.com/valyala/bytebufferpool with the backing slice kept unexported. Original source and MIT license remain at https://github.com/valyala/bytebufferpool.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Put

func Put(b *ByteBuffer)

Put returns byte buffer to the pool.

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

Types

type ByteBuffer

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

ByteBuffer provides a byte buffer that minimizes allocations.

Use Get for obtaining an empty byte buffer.

func Ensure

func Ensure(size int) *ByteBuffer

Ensure returns a byte buffer with at least the requested capacity.

func Get

func Get() *ByteBuffer

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 (*ByteBuffer) Bytes

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

Bytes returns the accumulated bytes in the buffer.

The returned slice aliases the internal buffer.

func (*ByteBuffer) Len

func (b *ByteBuffer) Len() int

Len returns the size of the byte buffer.

func (*ByteBuffer) ReadFrom

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

ReadFrom implements io.ReaderFrom by appending all data read from r.

func (*ByteBuffer) Reset

func (b *ByteBuffer) Reset()

Reset makes the buffer empty.

func (*ByteBuffer) Set

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

Set replaces the buffer contents with p.

func (*ByteBuffer) SetString

func (b *ByteBuffer) SetString(s string)

SetString replaces the buffer contents with s.

func (*ByteBuffer) String

func (b *ByteBuffer) String() string

String returns the string representation of the buffer contents.

func (*ByteBuffer) Write

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

Write implements io.Writer by appending p to the buffer.

func (*ByteBuffer) WriteByte

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

WriteByte appends the byte c to the buffer.

The function always returns nil.

func (*ByteBuffer) WriteString

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

WriteString appends s to the buffer.

func (*ByteBuffer) WriteTo

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

WriteTo implements io.WriterTo.

type Pool

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

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) Ensure

func (p *Pool) Ensure(size int) *ByteBuffer

Ensure returns a buffer with capacity at least size.

func (*Pool) Get

func (p *Pool) Get() *ByteBuffer

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 *ByteBuffer)

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