pub fn assert_max_allocations<F: FnOnce()>(
    max_allocations: u64,
    run_while_counting: F
)
Expand description

Run a closure and assert that the number of memory allocations are below a limit.

Will only measure those done by the current thread, so take care when testing the memory allocations of multithreaded code.

Arguments

  • max_allocations - The maximum number of allocations allowed
  • run_while_counting - The code to run while counting allocations

Examples

allocation_counter::assert_max_allocations(12, || {
    code_that_should_not_allocate_much();
});