bytepool

package module
v0.0.0-...-12e90da Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 5 Imported by: 0

README

bytepool

Go Reference

Purpose

Allocations getting you down?

  • Centralized byte pool interface
  • Optimizations/additions on existing pool packages
  • Support for variable and constant sizes

Usage

If you can choose some size bounds, prefer:

pool := bytepool.NewBucket(10, 100_000)

b := pool.Get()
defer b.Put(b)

// use buffer
b.B = append(b.B, 1,2,3) 
writeData(b.B)

If you don't know any bounds:

pool := bytepool.NewDynamic()

// use

If the buffer is usually one size:

pool := bytepool.NewSync()

// use

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bytes

type Bytes struct {
	B []byte
}

type Pooler

type Pooler interface {
	// Bytes with zero length. If giving back to pool, the
	// original pointer should be Put.
	Get() *Bytes

	SizedPooler
}

func NewDynamic

func NewDynamic() Pooler

Continually tunes the Get allocation size and max Put size. Suitable for variable sized Bytes, but at a cost.

func NewSync

func NewSync() Pooler

Suitable for similar sized Bytes otherwise pooled Bytes can trend to the largest, wasting memory. Direct sync.Pool implementation.

type SizedPooler

type SizedPooler interface {
	// Bytes with zero length and minimum capacity c. If giving back
	// to pool, the original pointer should be Put.
	GetGrown(c int) *Bytes

	// Can be nil. Do not use Bytes after Put.
	Put(*Bytes)
}

func NewBucket

func NewBucket(minSize, maxSize int) SizedPooler

Suitable for variable sized Bytes if max bounds can be chosen. Uses buckets of sizes that increase with the power of two. Puts over maxSize will be allocated directly.

Jump to

Keyboard shortcuts

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