Skip to main content

Module memory

Module memory 

Source
Expand description

§Memory Management

This module provides efficient memory management utilities for scientific computing.

§Features

  • Chunk processing for large datasets
  • Buffer pool for memory reuse
  • Zero-copy transformations
  • Memory usage tracking and metrics
  • Detailed memory allocation analysis

§Usage

use scirs2_core::memory::{ChunkProcessor2D, BufferPool};
use ::ndarray::Array2;

// Process a large array in chunks
let large_array = Array2::<f64>::zeros((10000, 10000));
let mut processor = ChunkProcessor2D::new(&large_array, (1000, 1000));

processor.process_chunks(|chunk, coords| {
    // Process each chunk (e.g., compute statistics, apply transformations)
    println!("Processing chunk at position {:?}", coords);
});

// Use a buffer pool to reuse memory
let mut pool = BufferPool::<f64>::new();

// Acquire a buffer from the pool
let mut buffer = pool.acquire_vec(1000);

// Use the buffer for some computation
for i in 0..buffer.len() {
    buffer[i] = i as f64;
}

// Release the buffer back to the pool when done
pool.release_vec(buffer);

// Track memory usage with the metrics system
use scirs2_core::memory::metrics::{track_allocation, track_deallocation, format_memory_report};

// Record an allocation
track_allocation("MyComponent", 1024, 0x1000);

// Record a deallocation
track_deallocation("MyComponent", 1024, 0x1000);

// Print a memory usage report
println!("{}", format_memory_report());

Re-exports§

pub use metrics::format_memory_report;
pub use metrics::generate_memory_report;
pub use metrics::track_allocation;
pub use metrics::track_deallocation;
pub use metrics::track_resize;
pub use leak_detection::LeakCheckGuard;
pub use leak_detection::LeakDetectionConfig;
pub use leak_detection::LeakDetector;
pub use leak_detection::LeakReport;
pub use leak_detection::LeakType;
pub use leak_detection::MemoryCheckpoint;
pub use leak_detection::MemoryLeak;
pub use leak_detection::ProfilerTool;
pub use leak_detection::ValgrindIntegration;

Modules§

compressed_buffers
Compressed memory buffers for memory-constrained environments
cross_device
Cross-device memory management for CPU/GPU/TPU
leak_detection
Memory leak detection and monitoring system
metrics
Advanced memory metrics system Memory metrics system for tracking and analyzing memory usage
out_of_core
Out-of-core processing for datasets larger than memory
safety
Production-level memory safety features with bounds checking and overflow protection

Structs§

AdvancedBufferPool
Advanced memory buffer pool with multiple allocation strategies
AllocationMetrics
Performance metrics for allocation strategies
BandwidthOptimizer
Memory bandwidth optimizer for scientific computing
BufferPool
Memory buffer pool for reusing allocated memory (legacy compatibility)
ChunkProcessor
A processor for working with large arrays in manageable chunks
ChunkProcessor2D
A specialized chunk processor for 2D arrays
GlobalBufferPool
Shared global buffer pool for different types
MemoryConfig
Configuration for advanced memory management
MemoryReport
Memory usage report
MemoryTracker
Memory usage tracker for monitoring memory consumption
PoolStatistics
Statistics for memory pool performance
SmartAllocator
Smart memory allocator that adapts to usage patterns
ZeroCopyView
Zero-copy array view for efficient data transformations

Enums§

AccessPattern
Memory access patterns for optimization hints
AllocationStrategy
Advanced memory allocation strategies
MemoryPressure
Memory pressure levels for adaptive behavior

Functions§

create_large_data_pool
Convenience function to create a memory pool optimized for large datasets
create_optimized_pool
Convenience function to create an optimized memory pool
create_scientific_pool
Convenience function to create a high-performance memory pool for scientific computing
global_bandwidth_optimizer
Get the global bandwidth optimizer
global_buffer_pool
Static global buffer pool instance
global_memory_tracker
Static global memory tracker instance
global_smart_allocator
Get the global smart allocator