bytespool

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package bytespool provides a pool of reusable byte slices organized by size classes.

The pool maintains separate sync.Pool instances for different buffer sizes, minimizing memory waste by selecting the smallest size class that fits the requested size. This avoids repeated allocations in hot paths.

The implementation uses a wrapper-reuse technique: *[]byte pointers are recycled between Get and Put via a secondary pool, achieving zero allocations in steady state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(size int) []byte

Get returns a byte slice with length == size from the pool. The returned slice may have a capacity larger than size. If size exceeds the maximum pooled size (65536), a new slice is allocated directly.

func Put

func Put(buf []byte)

Put returns a byte slice to the pool for reuse. Slices larger than the maximum pooled size or with zero capacity are silently discarded. The caller must not use the slice after calling Put.

Types

This section is empty.

Jump to

Keyboard shortcuts

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