laminar_core/alloc/mod.rs
1//! Zero-allocation enforcement for Ring 0 hot path.
2//!
3//! This module provides tools to detect and prevent heap allocations in
4//! latency-critical code paths. In Ring 0 (hot path), a single allocation
5//! can blow the <500ns latency budget.
6//!
7//! # Features
8//!
9//! - **Allocation Detector**: Custom allocator that panics on allocation in marked sections
10//! - **Hot Path Guard**: RAII guard to mark hot path sections
11//! - **Object Pool**: Pre-allocated object pool for zero-allocation acquire/release
12//! - **Ring Buffer**: Fixed-capacity ring buffer for event queues
13//! - **Scratch Buffer**: Thread-local temporary storage
14//!
15//! # Usage
16//!
17//! ```rust,ignore
18//! use laminar_core::alloc::{HotPathGuard, ObjectPool};
19//!
20//! // Mark a section as hot path (panics on allocation in debug builds)
21//! fn process_event(event: &Event) {
22//! let _guard = HotPathGuard::enter("process_event");
23//! // Any allocation here will panic in debug builds with allocation-tracking
24//! }
25//!
26//! // Use pre-allocated pools instead of heap allocation
27//! let mut pool: ObjectPool<MyType, 64> = ObjectPool::new();
28//! let obj = pool.acquire().unwrap();
29//! pool.release(obj);
30//! ```
31//!
32//! # Feature Flags
33//!
34//! Enable `allocation-tracking` feature to activate allocation detection:
35//!
36//! ```toml
37//! [dependencies]
38//! laminar-core = { version = "0.1", features = ["allocation-tracking"] }
39//! ```
40
41mod detector;
42mod guard;
43mod object_pool;
44mod ring_buffer;
45mod scratch;
46
47pub use detector::AllocationStats;
48pub use guard::HotPathGuard;
49pub use object_pool::ObjectPool;
50pub use ring_buffer::RingBuffer;
51pub use scratch::ScratchBuffer;
52
53// Re-export feature-gated items
54#[cfg(feature = "allocation-tracking")]
55pub use detector::{is_hot_path_enabled, set_panic_on_alloc, HotPathDetectingAlloc};