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: ? modules, 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

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