memory

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferPool

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

BufferPool manages buffers of a specific size range

type Config

type Config struct {
	// Buffer pool sizes
	SmallBufferSize  int // Default: 4KB
	MediumBufferSize int // Default: 32KB
	LargeBufferSize  int // Default: 256KB

	// Pool limits
	MaxSmallBuffers  int // Default: 1000
	MaxMediumBuffers int // Default: 500
	MaxLargeBuffers  int // Default: 100

	// Cleanup intervals
	CleanupInterval time.Duration // Default: 30s

	// Memory pressure thresholds
	MemoryPressureThreshold float64 // Default: 0.8 (80% of available memory)
	GCTriggerThreshold      float64 // Default: 0.9 (90% of available memory)
}

Config defines memory manager configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default memory manager configuration

type HeaderPool

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

HeaderPool manages header map objects

type Manager

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

Manager provides intelligent memory management with monitoring and optimization

func NewManager

func NewManager(config *Config) *Manager

NewManager creates a new memory manager

func (*Manager) Close

func (m *Manager) Close() error

Close shuts down the memory manager

func (*Manager) GetBuffer

func (m *Manager) GetBuffer(size int) []byte

GetBuffer returns a buffer of appropriate size

func (*Manager) GetHeaders

func (m *Manager) GetHeaders() map[string]string

GetHeaders returns a header map from the pool

func (*Manager) GetPooledRequest

func (m *Manager) GetPooledRequest() *PooledRequest

GetPooledRequest returns a pooled request object

func (*Manager) GetPooledResponse

func (m *Manager) GetPooledResponse() *PooledResponse

GetPooledResponse returns a pooled response object

func (*Manager) GetStats

func (m *Manager) GetStats() Stats

GetStats returns current memory statistics

func (*Manager) PutBuffer

func (m *Manager) PutBuffer(buf []byte)

PutBuffer returns a buffer to the appropriate pool

func (*Manager) PutHeaders

func (m *Manager) PutHeaders(headers map[string]string)

PutHeaders returns a header map to the pool

func (*Manager) PutPooledRequest

func (m *Manager) PutPooledRequest(req *PooledRequest)

PutPooledRequest returns a pooled request object

func (*Manager) PutPooledResponse

func (m *Manager) PutPooledResponse(resp *PooledResponse)

PutPooledResponse returns a pooled response object

type PooledRequest

type PooledRequest struct {
	Method      string
	URL         string
	Headers     map[string]string
	QueryParams map[string]interface{}
	Body        interface{}
	Timeout     time.Duration
	MaxRetries  int
	Context     interface{} // context.Context
}

PooledRequest represents a pooled request object

func (*PooledRequest) Reset

func (r *PooledRequest) Reset()

Reset clears the request for reuse

type PooledResponse

type PooledResponse struct {
	StatusCode    int
	Status        string
	Headers       map[string][]string
	Body          string
	RawBody       []byte
	ContentLength int64
	Proto         string
	Duration      time.Duration
	Attempts      int
}

PooledResponse represents a pooled response object

func (*PooledResponse) Reset

func (r *PooledResponse) Reset()

Reset clears the response for reuse

type RequestPool

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

RequestPool manages request objects

type ResponsePool

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

ResponsePool manages response objects

type Stats

type Stats struct {
	// Buffer pool statistics
	SmallBuffersInUse  int64
	MediumBuffersInUse int64
	LargeBuffersInUse  int64
	SmallBuffersTotal  int64
	MediumBuffersTotal int64
	LargeBuffersTotal  int64

	// Object pool statistics
	HeadersInUse   int64
	RequestsInUse  int64
	ResponsesInUse int64
	HeadersTotal   int64
	RequestsTotal  int64
	ResponsesTotal int64

	// Memory statistics
	AllocatedBytes int64
	SystemBytes    int64
	GCCycles       int64
	LastGCTime     int64

	// Performance metrics
	BufferHitRate  float64
	ObjectHitRate  float64
	MemoryPressure float64

	// Timestamps
	LastUpdate int64
}

Stats provides memory usage statistics

Jump to

Keyboard shortcuts

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