bufpool

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package bufpool initializes an elastic pool of free buffers. Buffer have capacity common.MaxMTU.

Apps can use bufpool to ammortize allocations between multiple goroutines without preallocating a large amount of memory. Details about how the allocation and freeing of resources works can be found in the documentation for sync.Pool.

For apps where the performance penalty of grabbing a single free buffer is non-neglibile (e.g., per packet processing in a router), package ringbuf (and manual management of free buffers) should be used instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Put

func Put(buffer *Buffer)

Put resets a buffer to its initial length and capacity and returns it to the free buffer pool.

Types

type Buffer

type Buffer struct {
	B common.RawBytes
	// contains filtered or unexported fields
}

Buffer is a container for a common.RawBytes object B. B can be safely resliced. Calling Reset will return B to its initial length and capacity.

func Get

func Get() *Buffer

Get returns a buffer from the free buffer pool. If a buffer is not available, a new one is allocated.

func (*Buffer) CloneB

func (b *Buffer) CloneB() common.RawBytes

CloneB returns a copy of the data in b.B.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset restores b.B to its initial length and capacity.

Jump to

Keyboard shortcuts

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