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§
- Advanced
Buffer Pool - Advanced memory buffer pool with multiple allocation strategies
- Allocation
Metrics - Performance metrics for allocation strategies
- Bandwidth
Optimizer - Memory bandwidth optimizer for scientific computing
- Buffer
Pool - Memory buffer pool for reusing allocated memory (legacy compatibility)
- Chunk
Processor - A processor for working with large arrays in manageable chunks
- Chunk
Processor2D - A specialized chunk processor for 2D arrays
- Global
Buffer Pool - Shared global buffer pool for different types
- Memory
Config - Configuration for advanced memory management
- Memory
Report - Memory usage report
- Memory
Tracker - Memory usage tracker for monitoring memory consumption
- Pool
Statistics - Statistics for memory pool performance
- Smart
Allocator - Smart memory allocator that adapts to usage patterns
- Zero
Copy View - Zero-copy array view for efficient data transformations
Enums§
- Access
Pattern - Memory access patterns for optimization hints
- Allocation
Strategy - Advanced memory allocation strategies
- Memory
Pressure - 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