bufferpool

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxBufferSize is the maximum buffer capacity before dropping.
	// Buffers larger than this are discarded to prevent memory bloat.
	MaxBufferSize = 1 << 20 // 1 MiB

	// DefaultCapacity is the initial capacity hint for new buffers.
	// This reduces reallocations for typical log entry sizes.
	DefaultCapacity = 512 // 512 bytes
)

Configuration constants for buffer pool behavior

Variables

This section is empty.

Functions

func Get

func Get() *bytes.Buffer

Get restituisce un *bytes.Buffer pulito (Reset) dal pool. Incrementa automaticamente le statistiche e garantisce che il buffer sia pronto per l'uso immediato senza contenuti precedenti.

func Put

func Put(b *bytes.Buffer)

Put restituisce il buffer al pool. Se il buffer è cresciuto troppo, lo azzera per evitare growth non controllato della memoria. Questa strategia bilancia performance e utilizzo memoria.

func ResetStats

func ResetStats()

ResetStats resets all pool statistics to zero. Useful for benchmarking and testing scenarios.

Types

type Stats

type Stats struct {
	Gets        int64 // Total number of Get() calls
	Puts        int64 // Total number of Put() calls
	Allocations int64 // Total number of new buffer allocations
	Drops       int64 // Total number of oversized buffers dropped
}

Stats returns current buffer pool statistics for monitoring. Useful for debugging memory usage and pool efficiency.

func GetStats

func GetStats() Stats

GetStats returns a snapshot of current pool statistics. Thread-safe and can be called from multiple goroutines.

Jump to

Keyboard shortcuts

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