buffer

package
v1.1.15 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package buffer provides a sync.Pool-backed implementation of httputil.BufferPool for reusing byte slices, aiming to save memory and reduce GC pressure when dealing with large response bodies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool implements httputil.Pool backed by a sync.Pool internally. It reduces allocations for large response bodies by reusing byte slices, thus lowering GC pressure.

func NewPool

func NewPool(minSize, maxSize int) *Pool

NewPool creates a new Pool that returns buffers of at least minSize bytes. Buffers that grow beyond maxSize will be discarded.

Both numbers must be positive, or else the function panics; minSize will be clamped by maxSize.

func (*Pool) Get

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

Get returns a reusable buffer slice.

func (*Pool) Put

func (b *Pool) Put(buf []byte)

Put returns the buffer to the pool unless it grew beyond the size limit.

Jump to

Keyboard shortcuts

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