bytespool

package
Version: v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2018 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPool = NewBytesPool()

DefaultPool is a default BytesBool instance.

Functions

This section is empty.

Types

type BytesPool

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

BytesPool maintains large bytes pools, used for reducing memory allocation. It has a slice of pools which handle different size of bytes. Can be safely used concurrently.

func NewBytesPool

func NewBytesPool() *BytesPool

NewBytesPool creates a new bytes pool.

func (*BytesPool) Alloc

func (bp *BytesPool) Alloc(size int) (origin, data []byte)

Alloc allocates a bytes which has the size of power of two. The caller should keep the origin bytes and use the returned data. When finished using, the origin bytes should be freed to the pool. The allocated data may not have zero value.

func (*BytesPool) Free

func (bp *BytesPool) Free(origin []byte) int

Free frees the data which should be the original bytes return by Alloc. It returns the bucket index of the data. returns -1 means the data is not returned to the pool.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL