Thanks to visit codestin.com
Credit goes to pkg.go.dev

pbytes

package
v1.6.7 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: Apache-2.0, MIT Imports: 1 Imported by: 1

Documentation

Overview

Package pbytes contains tools for pooling byte pool. Note that by default it reuse slices with capacity from 128 to 65536 bytes.

Index

Constants

This section is empty.

Variables

View Source
var DefaultPool = New(65536)

DefaultPool is used by pacakge level functions.

Functions

func Get

func Get(c int) *[]byte

Get returns probably reused slice of bytes with capacity of c. Get is a wrapper around DefaultPool.Get().

func Put

func Put(p *[]byte)

Put returns given slice to reuse pool. Put is a wrapper around DefaultPool.Put().

Types

type Pool

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

Pool contains logic of reusing byte slices of various size.

func New

func New(max int) *Pool

New creates new Pool that reuses slices which size

func (*Pool) Get

func (p *Pool) Get(c int) *[]byte

Get returns probably reused slice of bytes with capacity of c.

func (*Pool) Put

func (p *Pool) Put(bts *[]byte)

Put returns given slice to reuse pool. It does not reuse bytes whose size is not power of two or is out of pool min/max range.

Jump to

Keyboard shortcuts

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