bufferpool

package
v0.0.0-...-119448c Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2018 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer contains a byte buffer that can be released into a Pool for reuse.

Buffer is reference counted, and can be retained and released appropriately. Failure to release Buffer will not cause a memory leak, but will prevent the reuse of the Buffer.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns this buffer's byte slice.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the number of bytes in the buffer.

func (*Buffer) Release

func (b *Buffer) Release()

Release returns the buffer to its buffer pool.

Release is safe for concurrent use.

A Buffer must only be released once.

func (*Buffer) Retain

func (b *Buffer) Retain()

Retain increases the Buffer's reference count. It should be accompanied by a Release call to reuse the buffer when it's finished.

func (*Buffer) Truncate

func (b *Buffer) Truncate(size int)

Truncate artificially caps the number of bytes returned by Bytes.

type Pool

type Pool struct {
	// Size is the size of the buffers in this pool.
	Size int
	// contains filtered or unexported fields
}

Pool maintains a pool of buffers. It offers a new buffer when one is unavailable.

func (*Pool) Get

func (bp *Pool) Get() *Buffer

Get returns a buffer, allocating one if one is not available. The returned buffer is Reset and returned with a reference count of 1.

The caller should return the buffer to the pool by calling its Release method when done with it.

Jump to

Keyboard shortcuts

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