bufferpool

package
v0.0.0-...-202847b Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: Apache-2.0 Imports: 4 Imported by: 8 modules, 80 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bufferpool implements a pool of reusable auto-resizing buffers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get() *bytes.Buffer

Get returns a buffer from the pool.

func GetReader

func GetReader(b []byte) *bytes.Reader

Get returns a byte reader from the pool.

func New

func New(size int) tank

New instantiates a new bytes.Buffer pool with a custom pre-allocated buffer size.

func NewTwin

func NewTwin(size int) twinTank

NewTwin instantiates a new TwinBuffer pool with a custom pre-allocated buffer size. The fields `First` and `Second` will have the same size.

func Put

func Put(buf *bytes.Buffer)

Put returns a buffer to the pool. The buffer is reset before it is put back into circulation.

func PutReader

func PutReader(r *bytes.Reader)

Put returns a byte reader to the pool. The reader is reset before it is put back into circulation.

func PutTwin

func PutTwin(buf *TwinBuffer)

PutTwin returns a twin buffer to the pool. The buffers get reset before they are put back into circulation.

func PutTwinCallBack

func PutTwinCallBack(buf *TwinBuffer, fn func())

PutTwinCallBack same as PutTwin but executes fn after buf has been returned into the pool.

buf := twinBuf.Get()
defer twinBuf.PutCallBack(buf, wg.Done)

Types

type TwinBuffer

type TwinBuffer struct {
	First  *bytes.Buffer
	Second *bytes.Buffer
}

TwinBuffer contains two buffers.

func GetTwin

func GetTwin() *TwinBuffer

GetTwin returns a buffer containing two buffers, `First` and `Second`, from the pool.

func (*TwinBuffer) CopyFirstToSecond

func (tw *TwinBuffer) CopyFirstToSecond() (n int64, err error)

CopyFirstToSecond resets the second buffer and copies the content from the first buffer to the second buffer. First buffer gets eventually reset.

func (*TwinBuffer) CopySecondToFirst

func (tw *TwinBuffer) CopySecondToFirst() (n int64, err error)

CopySecondToFirst resets the first buffer and copies the content from the second buffer to the first buffer. Second buffer gets eventually reset.

func (*TwinBuffer) Reset

func (tw *TwinBuffer) Reset()

Reset resets both buffers.

func (*TwinBuffer) String

func (tw *TwinBuffer) String() string

String prints the buffers content for debug purposes.

func (*TwinBuffer) Write

func (tw *TwinBuffer) Write(p []byte) (n int, err error)

Write writes to both buffers one after another.

Jump to

Keyboard shortcuts

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