bufferpool

package
v0.0.0-...-5cfa2d5 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2021 License: Apache-2.0, MIT Imports: 2 Imported by: 3

README

bufferpool

Very simple bytes.Buffer pool using sync.Pool.

I got tired of writing the same sync.Pool for byte.Buffer objects.

SYNOPSIS

import "github.com/lestrrat-go/bufferpool"

var pool = bufferpool.New()

func main() {
    buf := pool.Get()
    defer pool.Release(buf)

    // ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get() *bytes.Buffer

Get returns a bytes.Buffer from a global pool

func Release

func Release(buf *bytes.Buffer)

Release puts the given bytes.Buffer instance back in the global pool.

Types

type BufferPool

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

BufferPool is a sync.Pool for bytes.Buffer objects

func New

func New() *BufferPool

New creates a new BufferPool instance

func (*BufferPool) Get

func (bp *BufferPool) Get() *bytes.Buffer

Get returns a bytes.Buffer from the specified pool

func (*BufferPool) Release

func (bp *BufferPool) Release(buf *bytes.Buffer)

Release puts the given bytes.Buffer back in the specified pool after resetting it

Jump to

Keyboard shortcuts

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