bytebufferpool

package
v0.0.0-...-4336771 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 4 Imported by: 0

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.

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

Types

type ByteBuffer

type ByteBuffer struct {

	// B 是在类似于追加的工作负载中使用的字节缓冲区。
	B []byte
}

ByteBuffer 提供字节缓冲区,可用于最小化内存分配。

ByteBuffer 可以与向给定的[]byte追加数据的函数一起使用 使用Get获取空字节缓冲区。

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 返回b.B,即缓冲区中累计的所有字节。

The purpose of this function is bytes.Buffer compatibility.

func (*ByteBuffer) Len

func (b *ByteBuffer) Len() int

Len 返回字节缓冲区的大小。

func (*ByteBuffer) ReadFrom

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

ReadFrom 实现 io.ReaderFrom.

返回字节缓冲区的大小。 该函数将从r读取的所有数据追加到b。

func (*ByteBuffer) Reset

func (b *ByteBuffer) Reset()

Reset makes ByteBuffer.B empty.

func (*ByteBuffer) Set

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

Set sets ByteBuffer.B to p.

func (*ByteBuffer) SetString

func (b *ByteBuffer) SetString(s string)

SetString sets ByteBuffer.B to s.

func (*ByteBuffer) String

func (b *ByteBuffer) String() string

String returns string representation of ByteBuffer.B.

func (*ByteBuffer) Write

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

Write 实现 io.Writer - it appends p to ByteBuffer.B

func (*ByteBuffer) WriteByte

func (b *ByteBuffer) 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 (*ByteBuffer) WriteString

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

WriteString appends s to ByteBuffer.B.

func (*ByteBuffer) WriteTo

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

WriteTo 实现 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() *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