pool

package
v0.0.0-...-a85f282 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BSONBatch

type BSONBatch *[]bson.M

BSONBatch 是 *[]bson.M 类型的别名

type BSONFactory

type BSONFactory struct {
	PoolSize int
}

BSONFactory 实现 ObjectFactory 接口,用于创建和重置 BSONBatch 对象

func NewBSONFactory

func NewBSONFactory(poolSize int) *BSONFactory

NewBSONFactory 构造函数

func (*BSONFactory) New

func (f *BSONFactory) New() BSONBatch

New 创建新的 BSON 对象

func (*BSONFactory) Reset

func (f *BSONFactory) Reset(batch BSONBatch)

Reset 重置 BSON 对象

type BatchPool

type BatchPool[T any] struct {
	Pool     sync.Pool
	PoolSize int
}

BatchPool 泛型对象池

func NewBatchPool

func NewBatchPool[T any](factory ObjectFactory[T], poolSize int) *BatchPool[T]

NewBatchPool 初始化一个泛型对象池

func (*BatchPool[T]) Get

func (bp *BatchPool[T]) Get() T

Get 获取对象

func (*BatchPool[T]) Put

func (bp *BatchPool[T]) Put(item T, factory ObjectFactory[T])

Put 放置对象

func (*BatchPool[T]) SetPoolSize

func (bp *BatchPool[T]) SetPoolSize(factory ObjectFactory[T], poolSize int)

SetPoolSize 更新池子的大小

type BufferFactory

type BufferFactory struct {
	BufferSize int
}

BufferFactory 实现 ObjectFactory 接口,用于创建和重置缓冲区

func NewBufferFactory

func NewBufferFactory(bufferSize int) *BufferFactory

NewBufferFactory 构造函数

func (*BufferFactory) New

func (f *BufferFactory) New() []byte

New 创建新的缓冲区

func (*BufferFactory) Reset

func (f *BufferFactory) Reset(buffer []byte)

Reset 重置缓冲区

type ObjectFactory

type ObjectFactory[T any] interface {
	New() T
	Reset(T)
}

ObjectFactory 定义对象创建和重置方法的接口

Jump to

Keyboard shortcuts

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