bufferpool

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(size int) *bytes.Buffer

func Init

func Init(strategy Strategy)

func Put

func Put(buf *bytes.Buffer)

Types

type Bucket

type Bucket interface {
	// 桶内没有Buffer对象时,返回nil
	Get() *bytes.Buffer

	Put(buf *bytes.Buffer)
}

type BufferPool

type BufferPool interface {
	// 获取一个预估容量为<size>的Buffer对象,不同的策略返回的Buffer对象实际容量可能会有不同,但是不会返回nil
	Get(size int) *bytes.Buffer

	// 将Buffer对象放回池中
	Put(buf *bytes.Buffer)

	// 获取池当前状态
	RetrieveStatus() Status
}

func NewBufferPool

func NewBufferPool(strategy Strategy) BufferPool

type SliceBucket

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

func NewSliceBucket

func NewSliceBucket() *SliceBucket

func (*SliceBucket) Get

func (b *SliceBucket) Get() *bytes.Buffer

func (*SliceBucket) Put

func (b *SliceBucket) Put(buf *bytes.Buffer)

type Status

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

func RetrieveStatus

func RetrieveStatus() Status

type StdPoolBucket

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

func NewStdPoolBucket

func NewStdPoolBucket() *StdPoolBucket

func (*StdPoolBucket) Get

func (b *StdPoolBucket) Get() *bytes.Buffer

func (*StdPoolBucket) Put

func (b *StdPoolBucket) Put(buf *bytes.Buffer)

type Strategy

type Strategy int
const (
	// 直接使用一个标准库中的sync.Pool
	StrategySingleStdPoolBucket Strategy = iota + 1

	// 直接使用一个切片存储所有的Buffer对象
	StrategySingleSlicePoolBucket

	// 按Buffer对象的容量哈希到不同的桶中,每个桶是一个sync.Pool
	StrategyMultiStdPoolBucket

	// 按Buffer对象的容量哈希到不同的桶中,每个桶是一个切片
	StrategyMultiSlicePoolBucket
)

Jump to

Keyboard shortcuts

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