buffer

package module
v0.0.0-...-05324a7 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2016 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package buffer provides pool of custom byte buffers.

It is just ByteBuffer extracted from github.com/valyala/fasthttp.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Release

func Release(b *Buffer)

Release returns byte buffer to the pool.

Buffer.B mustn't be touched after returning it to the pool. Otherwise data races occur.

Types

type Buffer

type Buffer struct {

	// B is a byte buffer to use in append-like workloads.
	// See example code for details.
	B []byte
}

Buffer provides byte buffer, which can be used in order to minimize memory allocations.

ByteBuffer may be used with functions appending data to the given []byte slice. See example code for details.

Use AcquireByteBuffer for obtaining an empty byte buffer.

func Acquire

func Acquire() *Buffer

Acquire returns an empty byte buffer from the pool.

Acquired byte buffer may be returned to the pool via Release call. This reduces the number of memory allocations required for byte buffer management.

func (*Buffer) Append

func (b *Buffer) Append(p []byte) int

Append appends p to ByteBuffer.B and returns length of p

func (*Buffer) Grow

func (b *Buffer) Grow(s int)

Grow adds s to buffer length.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset makes ByteBuffer.B empty.

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (int, error)

Write implements io.Writer - it appends p to ByteBuffer.B

type Pool

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

Pool wraps sync.Pool for buffer management with different initial sizes. Empty value for Pool is usable.

func NewPool

func NewPool(size int) Pool

NewPool creates Pool with defined initial size.

func (*Pool) Acquire

func (p *Pool) Acquire() *Buffer

Acquire returns an empty byte buffer from the pool.

Acquired byte buffer may be returned to the pool via Release call. This reduces the number of memory allocations required for byte buffer management.

func (*Pool) Release

func (p *Pool) Release(b *Buffer)

Release returns byte buffer to the pool.

Buffer.B mustn't be touched after returning it to the pool. Otherwise data races occur.

Jump to

Keyboard shortcuts

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