bufpool

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: Unlicense Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BufferSize is the size of each buffer in the pool (1kb)
	BufferSize = units.Kb
)

Variables

View Source
var Pool = sync.Pool{
	New: func() interface{} {

		b := make([]byte, 0, BufferSize)

		return B(b)
	},
}

Functions

func Put

func Put(b B)

Put returns a buffer to the pool. Buffers should be returned to the pool when no longer needed to allow reuse.

func PutBytes

func PutBytes(b []byte)

PutBytes returns a buffer was not necessarily created by Get().

Types

type B

type B []byte

func Get

func Get() B

Get returns a buffer from the pool or creates a new one if the pool is empty.

Example usage:

buf := bufpool.Get()
defer bufpool.Put(buf)
// Use buf...

func (B) ToBytes

func (b B) ToBytes() []byte

Source Files

  • bufpool.go

Jump to

Keyboard shortcuts

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