baby_mimalloc/deferred_free.rs
1use crate::*;
2
3/// Handle to complete deferred free in [`DeferredFreeHook`].
4pub struct DeferredFreeHandle<'a, A: GlobalAlloc> {
5 pub(crate) heap: &'a mut Heap,
6 pub(crate) os_alloc: &'a A,
7}
8
9impl<A: GlobalAlloc> DeferredFreeHandle<'_, A> {
10 /// Deallocate the block of memory at the given `ptr`.
11 ///
12 /// # Safety
13 ///
14 /// See [`GlobalAlloc::dealloc`].
15 pub unsafe fn free(&mut self, ptr: *mut u8) {
16 self.heap.free(ptr, self.os_alloc);
17 }
18}
19
20/// Hook to complete deferred free when the allocator needs more memory.
21/// See [`DeferredFreeHandle`] and [`Mimalloc::register_deferred_free`].
22pub type DeferredFreeHook<A> = fn(handle: &mut DeferredFreeHandle<A>, force: bool, heartbeat: u64);