Skip to main content

MiMalloc

Struct MiMalloc 

Source
pub struct MiMalloc;
Expand description

The mimalloc global allocator.

Drop-in replacement for the system allocator. Always uses mi_malloc_aligned internally to guarantee correct alignment for all layouts.

Implementations§

Source§

impl MiMalloc

Source

pub fn version() -> i32

mimalloc version as major * 10000 + minor * 100 + patch.

Source

pub fn collect(force: bool)

Force garbage collection.

Source

pub unsafe fn usable_size(ptr: *const u8) -> usize

Usable size of an allocated block (may be larger than requested).

§Safety

ptr must have been allocated by mimalloc.

Source

pub unsafe fn free_csize(ptr: *mut u8, size: usize)

Free a mimalloc block when the allocation size is known.

For small sizes this uses mimalloc’s small-free fast path.

§Safety

ptr must be null or a valid mimalloc allocation, and size must be the allocation size used for the corresponding allocation.

Source

pub unsafe fn free_csize_nonnull(ptr: NonNull<u8>, size: usize)

Free a non-null mimalloc block when the allocation size is known.

For small sizes this uses mimalloc’s non-null small-free fast path.

§Safety

ptr must be a valid mimalloc allocation, and size must be the allocation size used for the corresponding allocation.

Source

pub unsafe fn free_small(ptr: *mut u8)

Free a small mimalloc block.

§Safety

ptr must be null or a valid mimalloc allocation whose allocation size is less than or equal to crate::MI_SMALL_SIZE_MAX.

Source

pub unsafe fn free_small_nonnull(ptr: NonNull<u8>)

Free a non-null small mimalloc block.

§Safety

ptr must be a valid mimalloc allocation whose allocation size is less than or equal to crate::MI_SMALL_SIZE_MAX.

Source

pub fn process_info() -> ProcessInfo

Process memory information.

Source

pub fn stats_json() -> String

Allocation statistics as JSON. Returns empty string on failure.

Source

pub fn stats_print() -> String

Allocation statistics in mimalloc’s human-readable text format.

Source

pub fn stats_reset()

Reset accumulated mimalloc allocation statistics.

Source

pub fn process_info_print() -> String

Process memory information in mimalloc’s human-readable text format.

Source

pub fn option_is_enabled(option: mi_option_t) -> bool

Check if an option is enabled.

Source

pub fn option_get(option: mi_option_t) -> c_long

Get an option value.

Source

pub fn option_get_size(option: mi_option_t) -> usize

Get an option value as size (bytes).

Source

pub fn option_set(option: mi_option_t, value: c_long)

Set an option value.

use rustfs_mimalloc::MiMalloc;
use rustfs_mimalloc_sys::mi_option_t;

// Return memory to OS immediately
MiMalloc::option_set(mi_option_t::mi_option_purge_delay, 0);
Source

pub fn option_enable(option: mi_option_t)

Enable an option.

Source

pub fn option_disable(option: mi_option_t)

Disable an option.

Trait Implementations§

Source§

impl Clone for MiMalloc

Source§

fn clone(&self) -> MiMalloc

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for MiMalloc

Source§

impl Debug for MiMalloc

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MiMalloc

Source§

fn default() -> MiMalloc

Returns the “default value” for a type. Read more
Source§

impl GlobalAlloc for MiMalloc

Source§

unsafe fn alloc(&self, layout: Layout) -> *mut u8

Allocates memory as described by the given layout. Read more
Source§

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 more
Source§

unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout)

Deallocates the block of memory at the given ptr pointer with the given layout. Read more
Source§

unsafe fn realloc( &self, ptr: *mut u8, layout: Layout, new_size: usize, ) -> *mut u8

Shrinks or grows a block of memory to the given new_size in bytes. The block is described by the given ptr pointer and layout. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.