memory

package
v0.20.2 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TarBufferSize is optimized for TAR file operations (64KB)
	TarBufferSize = 65536 // 64KB - optimized for tar operations

	// Maximum buffer size to retain in pool (prevents memory bloat)
	MaxRetainedBufferSize = 1048576 // 1MB
)

Variables

This section is empty.

Functions

func GetBuffer

func GetBuffer(size BufferSize) []byte

GetBuffer gets a TAR buffer from the default pool

func PutBuffer

func PutBuffer(buffer []byte, size BufferSize)

PutBuffer returns a buffer to the default pool

func TrackAllocation

func TrackAllocation(bytes int64)

TrackAllocation records an allocation using the default tracker

func TrackBufferReuse

func TrackBufferReuse()

TrackBufferReuse increments buffer reuse counter using the default tracker

func TrackOperation

func TrackOperation(duration time.Duration)

TrackOperation records an operation duration using the default tracker

func TrackStringReuse

func TrackStringReuse()

TrackStringReuse increments string reuse counter using the default tracker

func WithBuffer

func WithBuffer(size BufferSize, fn func([]byte))

WithBuffer executes a function with a pooled TAR buffer This ensures proper cleanup even if the function panics

func WithBufferReturn

func WithBufferReturn[T any](size BufferSize, fn func([]byte) T) T

WithBufferReturn executes a function with a pooled TAR buffer and returns a value This ensures proper cleanup even if the function panics

Types

type BufferPool

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

BufferPool manages reusable byte slices for TAR operations

func NewBufferPool

func NewBufferPool() *BufferPool

NewBufferPool creates a new BufferPool optimized for TAR operations

func (*BufferPool) Get

func (p *BufferPool) Get(size BufferSize) []byte

Get retrieves a TAR buffer from the pool

func (*BufferPool) GetMetrics

func (p *BufferPool) GetMetrics() BufferPoolMetrics

GetMetrics returns pool efficiency metrics

func (*BufferPool) Put

func (p *BufferPool) Put(buffer []byte, size BufferSize)

Put returns a buffer to the TAR pool

type BufferPoolMetrics

type BufferPoolMetrics struct {
	TarHits   int64
	TarMisses int64
}

BufferPoolMetrics contains statistics about buffer pool usage

func GetBufferPoolMetrics

func GetBufferPoolMetrics() BufferPoolMetrics

GetBufferPoolMetrics returns metrics for the default pool

func (BufferPoolMetrics) HitRate

func (m BufferPoolMetrics) HitRate() float64

HitRate calculates the hit rate for the TAR buffer pool

type BufferSize

type BufferSize int

BufferSize represents buffer size categories

const (
	TarBuffer BufferSize = iota
)

type MemoryTracker

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

MemoryTracker tracks basic memory usage metrics for pools

func NewMemoryTracker

func NewMemoryTracker() *MemoryTracker

NewMemoryTracker creates a new memory tracker instance

func (*MemoryTracker) TrackAllocation

func (mt *MemoryTracker) TrackAllocation(bytes int64)

TrackAllocation records an allocation event

func (*MemoryTracker) TrackBufferReuse

func (mt *MemoryTracker) TrackBufferReuse()

TrackBufferReuse increments buffer reuse counter

func (*MemoryTracker) TrackOperation

func (mt *MemoryTracker) TrackOperation(duration time.Duration)

TrackOperation records the duration of an operation

func (*MemoryTracker) TrackStringReuse

func (mt *MemoryTracker) TrackStringReuse()

TrackStringReuse increments string reuse counter

Jump to

Keyboard shortcuts

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