bytespool

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(buf []byte, elems ...byte) []byte

func AppendString

func AppendString(buf []byte, elems string) []byte

func Bytes

func Bytes(len, cap int) (b []byte)

Bytes allocates a byte slice but does not clean up the memory it references. Throw a fatal error instead of panic if cap is greater than runtime.maxAlloc. NOTE: MUST set any byte element before it's read. Ref: xiaost/bytedance-gopkg

func Get

func Get(size int) []byte

func Make

func Make(size int) []byte

func New

func New(size int) []byte

func NewBytes

func NewBytes(bs []byte) []byte

func NewString

func NewString(s string) []byte

func Put

func Put(buf []byte)

func Release

func Release(buf []byte) bool

func SetMaxSize

func SetMaxSize(size int) bool

SetMaxSize 设置回收时允许的最大字节

Types

type CapacityPools

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

func (*CapacityPools) Append

func (p *CapacityPools) Append(buf []byte, elems ...byte) []byte

Append 与内置的 append 功能相同, 当底层数组需要重建时, 会回收原数组

func (*CapacityPools) AppendString

func (p *CapacityPools) AppendString(buf []byte, elems string) []byte

func (*CapacityPools) Get

func (p *CapacityPools) Get(size int) []byte

Get 完全同 New()

func (*CapacityPools) Make

func (p *CapacityPools) Make(capacity int) []byte

Make 返回 len 为 0, cap >= 给定值的 []byte

func (*CapacityPools) New

func (p *CapacityPools) New(size int) (buf []byte)

New 返回指定长度的 []byte 注:

  1. 返回的 buf != nil
  2. 由于复用底层数组, buf 可能残留有旧数据

func (*CapacityPools) NewBytes

func (p *CapacityPools) NewBytes(bs []byte) []byte

NewBytes returns a byte slice of the specified content.

func (*CapacityPools) NewString

func (p *CapacityPools) NewString(s string) []byte

NewString returns a byte slice of the specified content.

func (*CapacityPools) Put

func (p *CapacityPools) Put(buf []byte)

Put 同 Release(), 不返回是否回收成功

func (*CapacityPools) Release

func (p *CapacityPools) Release(buf []byte) bool

Jump to

Keyboard shortcuts

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