pub unsafe fn unwrapped_malloc(size: usize, alignment: usize) -> *mut u8Expand description
Allocate size bytes from mimalloc’s raw-OS-layer “unwrapped” path.
Thin wrapper around mi_unwrapped_malloc (include/mimalloc/memory-events.h):
backed directly by _mi_os_alloc_aligned, never by the hooked mi_malloc
family. Page granular, so this is not meant for hot-path/small allocations
— it exists for low-level instrumentation and recursion avoidance (e.g.
scratch storage for a memory-change callback that must not recursively
enter mimalloc). Excluded from normal mimalloc allocation stats and from
the memory-change accounting.
Returns a null pointer on failure (including invalid alignment; see
# Safety below).
§Safety
alignmentmust be0(treated asalign_of::<*const ()>(), i.e. pointer size) or a power of two. A non-power-of-two, non-zero alignment is a validated input on the C side:mi_unwrapped_mallocreturns a null pointer rather than invoking undefined behavior, but callers should not rely on that as anything other than a defined-failure contract — treat the alignment argument as a precondition to get right, not a value to probe.- The returned pointer, if non-null, must be passed only to
unwrapped_freeorunwrapped_realloc— never tomi_free, this crate’sMiMallocallocator, or Rust’s global allocator, and vice versa (a pointer frommi_malloc/the Rust global allocator must never be passed tounwrapped_free/unwrapped_realloc). Mixing these families corrupts allocator-internal bookkeeping. - The memory is uninitialized; reading it before writing is undefined behavior, as with any raw allocation.