#[cfg(not(feature = "memory_management"))]
#[allow(dead_code)]
fn main() {
println!("This example requires the 'memory_management' feature to be enabled.");
println!(
"Run with: cargo run --example memory_metrics_bufferpool --features memory_management"
);
}
#[cfg(feature = "memory_management")]
use scirs2_core::memory::metrics::{
format_bytes, format_memory_report, reset_memory_metrics, TrackedBufferPool,
};
#[cfg(feature = "memory_management")]
use std::thread;
#[cfg(feature = "memory_management")]
use std::time::Duration;
#[cfg(feature = "memory_management")]
#[allow(dead_code)]
fn main() {
println!("Memory Metrics with TrackedBufferPool Example");
println!("=============================================\n");
reset_memory_metrics();
let mut pool = TrackedBufferPool::<f64>::new("NumericalComputation");
println!("Created TrackedBufferPool for numerical computations");
println!("\nAcquiring and releasing buffers:");
for i in 1..=5 {
let size = i * 1000;
let vec = pool.acquire_vec(size);
println!(
" Acquired vector of size {} ({})",
size,
format_bytes(size * 8)
);
thread::sleep(Duration::from_millis(100));
pool.release_vec(vec);
println!(" Released vector of size {}", size);
if i == 1 || i == 5 {
println!("\nMemory report after iteration {}:", i);
println!("{}", format_memory_report());
}
}
println!("\nWorking with ndarray objects:");
for i in 1..=3 {
let size = i * 5000;
let array = pool.acquire_array(size);
println!(
" Acquired array of size {} ({})",
size,
format_bytes(size * 8)
);
thread::sleep(Duration::from_millis(200));
pool.release_array(array);
println!(" Released array of size {}", size);
}
println!("\nFinal memory report:");
println!("{}", format_memory_report());
}