memory

package
v0.37.2 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 2 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 TrackBufferReuse

func TrackBufferReuse()

TrackBufferReuse increments buffer reuse counter using the default tracker

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) Put

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

Put returns a buffer to the TAR 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) TrackBufferReuse

func (mt *MemoryTracker) TrackBufferReuse()

TrackBufferReuse increments buffer reuse counter

Jump to

Keyboard shortcuts

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