bytepool

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package bytepool implements a pool of bytes using a seg list.

Index

Constants

View Source
const DefaultPoolChanSize = uint32(32)

DefaultPoolChanSize is the default pool channel size.

Variables

View Source
var DefaultListSizes = []uint32{
	8,
	16,
	64,
	256,
	512,
	1024,
	4096,
	8192,
	16384,
	32768,
	65536,
	131072,
	262144,
	524288,
	1048576,
	2097152,
	4194304,
	8388608,
	16777216,
}

DefaultListSizes are the default list sizes.

Functions

This section is empty.

Types

type Bytes

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

Bytes represents a byte slice.

Only create these from SegLists.

func (*Bytes) CopyFrom

func (b *Bytes) CopyFrom(from []byte, offset int) (int, error)

CopyFrom copies from the byte slice to the Bytes starting at the offset.

Returns io.EOF if len(from) + offset is greater than the buffer size.

func (*Bytes) CopyTo

func (b *Bytes) CopyTo(to []byte, offset int) (int, error)

CopyTo copies the from the Bytes to the byte slice starting at the offset.

Returns io.EOF if len(to) + offset is greater than Len().

func (*Bytes) Len

func (b *Bytes) Len() int

Len gets the current length.

func (*Bytes) Recycle

func (b *Bytes) Recycle()

Recycle recycles the Bytes.

Must be called when done.

type ListStats

type ListStats struct {
	// The list size.
	// 0 denotes no list.
	ListSize uint32
	// Number of times New was called on the sync.Pool.
	TotalNew uint64
	// Number of times Get was called on the *Pool.
	TotalGet uint64
	// Number of outstanding messages that were not recycled.
	TotalUnrecycled uint64
}

ListStats are stats.

type SegList

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

SegList is a seg list.

Only create with NewSegList.

func NewNoPoolSegList

func NewNoPoolSegList() *SegList

NewNoPoolSegList returns a new SegList that does no memory pooling.

func NewSegList

func NewSegList(options ...SegListOption) *SegList

NewSegList returns a new SegList.

func (*SegList) Get

func (s *SegList) Get(size uint32) *Bytes

Get gets a Bytes of at least the given size.

Returns nil if size == 0.

func (*SegList) ListStats

func (s *SegList) ListStats() []*ListStats

ListStats returns the list stats.

type SegListOption

type SegListOption func(*SegList)

SegListOption is an option for a new SegList

func SegListWithListSizes

func SegListWithListSizes(listSizes []uint32) SegListOption

SegListWithListSizes returns a SegListOption that uses the given list sizes.

The default is to use DefaultListSizes.

If listSizes is nil or empty, no lists will be used and all allocations will be done with make.

func SegListWithNoMemsetZero

func SegListWithNoMemsetZero() SegListOption

SegListWithNoMemsetZero returns a SegListOption that does not clear allocated buffers.

Only do this if you know what you are doing.

func SegListWithPoolChanSize

func SegListWithPoolChanSize(poolChanSize uint32) SegListOption

SegListWithPoolChanSize returns a SegListOption that uses the given pool channel size.

The default is to use DefaultPoolChanSize.

If poolChanSize is 0, no channel will be used and all allocations will be done with a sync.Pool.

Directories

Path Synopsis
Package bytepooltesting implements testing functionality for bytepool.
Package bytepooltesting implements testing functionality for bytepool.

Jump to

Keyboard shortcuts

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