bufpool

package
v0.0.0-...-466b026 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 1 Imported by: 0 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

Overview

Package bufpool holds buffers shared by networking helpers.

Index

Constants

View Source
const (
	// SmallSize fits common datagrams, such as the queued datagrams of a
	// connection, which take the room of several when larger.
	SmallSize = 2 << 10
	// StreamSize is the buffer a stream is copied through.
	StreamSize = 32 << 10
	// MaxDatagram is the largest UDP datagram.
	MaxDatagram = 65535
	// LargeSize fits the largest UDP datagram with room for a 2-byte length
	// ahead of it, as a frame header takes.
	LargeSize = 2 + MaxDatagram
)

Variables

View Source
var (
	Small  = &Pool{pool: sync.Pool{New: func() any { return NewBuf(SmallSize) }}, size: SmallSize}
	Stream = &Pool{pool: sync.Pool{New: func() any { return NewBuf(StreamSize) }}, size: StreamSize}
	Large  = &Pool{pool: sync.Pool{New: func() any { return NewBuf(LargeSize) }}, size: LargeSize}
)

The shared pools, initialised statically, so that a program that links this package without using them runs no initialisation for them.

Functions

func NewBuf

func NewBuf(n int) *[]byte

NewBuf returns a new buffer of n bytes.

func Release

func Release(bp *[]byte)

Release gives back a buffer of one of the shared pools or of a Queue, whatever its length now; one of another capacity is dropped.

Types

type Pool

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

Pool pools buffers of one size, each at its full length. Its methods are small enough to be inlined.

func (*Pool) Get

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

Get returns a buffer of p.Size() bytes.

func (*Pool) Put

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

Put gives back a buffer of Get, whatever its length now.

func (*Pool) Size

func (p *Pool) Size() int

Size returns the size of p's buffers.

Jump to

Keyboard shortcuts

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