[−][src]Crate interloc
interloc
This crate defines an interface for creating allocator middleware, i.e. code that runs when your allocator is run.
Examples
use interloc::{AllocMonitor, AllocAction, InterAlloc, StatsMonitor, ThreadMonitor}; use std::alloc::System; use core::alloc::Layout; struct MyMonitor { pub global: StatsMonitor, pub local: ThreadMonitor } impl MyMonitor { // This needs to be const to be usable in static functions pub const fn new() -> Self { Self { global: StatsMonitor::new(), local: ThreadMonitor::new(), } } } impl AllocMonitor for MyMonitor { fn monitor(&self, layout: Layout, action: AllocAction) { self.global.monitor(layout, action); self.local.monitor(layout, action); } } static MONITOR: MyMonitor = MyMonitor::new(); // This needs to be done at the project root #[global_allocator] static GLOBAL: InterAlloc<System, MyMonitor> = InterAlloc { inner: System, monitor: &MONITOR, };
Structs
AllocInfo | Information about allocs by the allocator |
InterAlloc | An allocator that watches the calls to its API, sends them to a struct, and then makes the calls. |
Layout | Layout of a block of memory. |
StatsMonitor | |
ThreadMonitor | Thread-local statistics on memory usage. |
Enums
AllocAction | An action that an allocator can take, either right before, or right after it happens. |
AllocRel | Before or after an allocation call is executed. |
Ordering | Atomic memory orderings |
Traits
AllocMonitor | An allocator monitor that can be used to monitor calls to the allocator. |
GlobalAlloc | A memory allocator that can be registered as the standard library’s default
though the |
Functions
fence | An atomic fence. |