pub struct CountingAllocator { /* private fields */ }Expand description
#[global_allocator]-compatible wrapper around the system
allocator that counts every successful allocation and
deallocation while a thread-shared TRACKING flag is set.
§Example
ⓘ
use taktora_bounded_alloc::CountingAllocator;
#[global_allocator]
static A: CountingAllocator = CountingAllocator::new();
fn main() {
A.reset();
A.set_tracking(true);
// ... measure a region of interest ...
A.set_tracking(false);
println!("allocs in region: {}", A.alloc_count());
}Implementations§
Source§impl CountingAllocator
impl CountingAllocator
Sourcepub fn set_tracking(&self, on: bool)
pub fn set_tracking(&self, on: bool)
Enable or disable counting. When false, allocations
pass through without incrementing the counters.
Sourcepub fn is_tracking(&self) -> bool
pub fn is_tracking(&self) -> bool
Is counting currently enabled?
Sourcepub fn alloc_count(&self) -> usize
pub fn alloc_count(&self) -> usize
Total successful allocations counted since the most
recent reset.
Sourcepub fn dealloc_count(&self) -> usize
pub fn dealloc_count(&self) -> usize
Total deallocations counted since the most recent reset.
Trait Implementations§
Source§impl Default for CountingAllocator
impl Default for CountingAllocator
Source§impl GlobalAlloc for CountingAllocator
impl GlobalAlloc for CountingAllocator
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
Allocates memory as described by the given
layout. Read moreSource§unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
Behaves like
alloc, but also ensures that the contents
are set to zero before being returned. Read moreAuto Trait Implementations§
impl !Freeze for CountingAllocator
impl RefUnwindSafe for CountingAllocator
impl Send for CountingAllocator
impl Sync for CountingAllocator
impl Unpin for CountingAllocator
impl UnsafeUnpin for CountingAllocator
impl UnwindSafe for CountingAllocator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more