Documentation
¶
Overview ¶
Package optimization provides performance optimization utilities
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrPoolClosed = &poolError{"pool is closed"}
ErrPoolClosed is returned when operating on a closed pool.
Functions ¶
This section is empty.
Types ¶
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool provides a pool of reusable byte buffers.
func (*BufferPool) Get ¶
func (p *BufferPool) Get() *bytes.Buffer
Get retrieves a buffer from the pool.
func (*BufferPool) Put ¶
func (p *BufferPool) Put(buf *bytes.Buffer)
Put returns a buffer to the pool.
type ByteSlicePool ¶
type ByteSlicePool struct {
// contains filtered or unexported fields
}
ByteSlicePool provides a pool of reusable byte slices.
func NewByteSlicePool ¶
func NewByteSlicePool() *ByteSlicePool
NewByteSlicePool creates a new byte slice pool.
func (*ByteSlicePool) Get ¶
func (p *ByteSlicePool) Get(size int) []byte
Get retrieves a byte slice of the specified size.
func (*ByteSlicePool) Put ¶
func (p *ByteSlicePool) Put(buf []byte)
Put returns a byte slice to the pool.
type ConnectionPool ¶
type ConnectionPool[T any] struct { // contains filtered or unexported fields }
ConnectionPool manages a pool of reusable connections.
func NewConnectionPool ¶
func NewConnectionPool[T any]( maxSize int, factory func() (T, error), reset func(T) error, closeFunc func(T) error, ) *ConnectionPool[T]
NewConnectionPool creates a new connection pool.
func (*ConnectionPool[T]) Close ¶
func (p *ConnectionPool[T]) Close() error
Close closes all connections in the pool.
func (*ConnectionPool[T]) Get ¶
func (p *ConnectionPool[T]) Get() (T, error)
Get retrieves a connection from the pool.
func (*ConnectionPool[T]) Put ¶
func (p *ConnectionPool[T]) Put(conn T) error
Put returns a connection to the pool.
func (*ConnectionPool[T]) Size ¶
func (p *ConnectionPool[T]) Size() int
Size returns the current number of connections in the pool.
type ObjectPool ¶
type ObjectPool[T any] struct { // contains filtered or unexported fields }
ObjectPool provides a generic object pool.
func NewObjectPool ¶
func NewObjectPool[T any](newFunc func() T) *ObjectPool[T]
NewObjectPool creates a new object pool.