bufpool

package
v0.44.4 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: Unlicense Imports: 2 Imported by: 0

Documentation

Overview

Package bufpool provides buffer pools for reducing GC pressure in hot paths.

Two pool sizes are provided:

  • SmallPool (64 bytes): For index keys, serial encoding, short buffers
  • MediumPool (1KB): For event encoding, larger serialization buffers

Usage:

buf := bufpool.GetSmall()
defer bufpool.PutSmall(buf)
// Use buf...
// IMPORTANT: Copy buf.Bytes() before Put if data is needed after

Index

Constants

View Source
const (
	// SmallBufferSize for index keys (8-64 bytes typical)
	SmallBufferSize = 64

	// MediumBufferSize for event encoding (300-1000 bytes typical)
	MediumBufferSize = 1024
)

Variables

This section is empty.

Functions

func CopyBytes

func CopyBytes(buf *bytes.Buffer) []byte

CopyBytes copies the buffer contents to a new slice. Use this before returning the buffer to the pool if the data needs to persist.

func GetMedium

func GetMedium() *bytes.Buffer

GetMedium returns a medium buffer (1KB) from the pool. Call PutMedium when done to return it to the pool.

WARNING: Copy buf.Bytes() before calling PutMedium if the data is needed after the buffer is returned to the pool.

func GetSmall

func GetSmall() *bytes.Buffer

GetSmall returns a small buffer (64 bytes) from the pool. Call PutSmall when done to return it to the pool.

WARNING: Copy buf.Bytes() before calling PutSmall if the data is needed after the buffer is returned to the pool.

func PutMedium

func PutMedium(buf *bytes.Buffer)

PutMedium returns a medium buffer to the pool. The buffer is reset before being returned.

func PutSmall

func PutSmall(buf *bytes.Buffer)

PutSmall returns a small buffer to the pool. The buffer is reset before being returned.

Types

This section is empty.

Source Files

  • pool.go

Jump to

Keyboard shortcuts

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