use std::time::Instant;
use memkit::{MkAllocator, MkConfig};
fn main() {
println!("=== memkit Basic Example ===\n");
let alloc = MkAllocator::new(MkConfig::default());
for frame_num in 0..3 {
println!("--- Frame {} ---", frame_num);
alloc.begin_frame();
if let Some(mut position) = alloc.frame_box([0.0f32, 1.0, 2.0]) {
println!(" Frame box: position = {:?}", *position);
position[0] = 10.0;
println!(" Modified: position = {:?}", *position);
}
if let Some(mut velocities) = alloc.frame_slice::<[f32; 3]>(4) {
println!(" Frame slice: {} velocities allocated", velocities.len());
for (i, v) in velocities.iter_mut().enumerate() {
*v = [i as f32, 0.0, 0.0];
}
}
if let Some(mut entities) = alloc.frame_vec::<u32>(10) {
entities.push(100);
entities.push(200);
entities.push(300);
println!(" Frame vec: {} entities", entities.len());
}
{
let _scope = alloc.scope();
let checkpoint = alloc.frame_head();
println!(" Scope checkpoint at: {}", checkpoint);
let _temp1 = alloc.frame_box(42u64);
let _temp2 = alloc.frame_box(123u64);
println!(" Inside scope: frame head = {}", alloc.frame_head());
}
println!(" After scope: frame head = {}", alloc.frame_head());
if let Some(pooled) = alloc.pool_box(String::from("Hello from pool!")) {
println!(" Pool box: {}", *pooled);
}
alloc.end_frame();
println!(" Frame ended, arena reset\n");
}
let stats = alloc.stats();
println!("=== Stats ===");
println!(" Frames: {}", stats.frame);
println!(" Total allocated: {} bytes", stats.total_allocated);
println!(" Peak allocated: {} bytes", stats.peak_allocated);
println!("\nDone!");
}