mimalloc_sys/
lib.rs

1//! Raw FFI wrapper over the mimalloc memory allocator
2#![no_std]
3use libc::{c_void, size_t, FILE, c_int};
4
5extern "C" {
6    // Standard malloc interface
7
8    pub fn mi_malloc(size: size_t) -> *mut c_void;
9    pub fn mi_calloc(count: size_t, size: size_t) -> *mut c_void;
10    pub fn mi_realloc(p: *mut c_void, newsize: size_t) -> *mut c_void;
11    pub fn mi_expand(p: *mut c_void, newsize: size_t) -> *mut c_void;
12    pub fn mi_posix_memalign(ptr: *mut *mut c_void, alignment: size_t, size: size_t) -> c_int;
13    pub fn mi_aligned_alloc(alignment: size_t, size: size_t) -> *mut c_void;
14    pub fn mi_free(p: *mut c_void);
15    pub fn mi_malloc_size(p: *const c_void) -> size_t;
16    pub fn mi_malloc_usable_size(p: *const c_void) -> size_t;
17
18    // Extended functionality
19
20    pub fn mi_zalloc(size: size_t) -> *mut c_void;
21    pub fn mi_usable_size(p: *const c_void) -> size_t;
22    pub fn mi_good_size(size: size_t) -> size_t;
23
24    pub fn mi_collect(force: bool);
25    pub fn mi_stats_print(out: *mut FILE);
26    pub fn mi_stats_reset();
27
28    // Aligned allocation
29
30    pub fn mi_malloc_aligned(size: size_t, alignment: size_t) -> *mut c_void;
31    pub fn mi_zalloc_aligned(size: size_t, alignment: size_t) -> *mut c_void;
32    pub fn mi_calloc_aligned(
33        count: size_t,
34        size: size_t,
35        alignment: size_t,
36    ) -> *mut c_void;
37    pub fn mi_realloc_aligned(
38        p: *mut c_void,
39        newsize: size_t,
40        alignment: size_t,
41    ) -> *mut c_void;
42}
43
44#[cfg(feature = "override")]
45extern "C" {
46    // When the override feature is enabled, we also expose the standard C API here.
47    pub fn malloc(size: size_t) -> *mut c_void;
48    pub fn calloc(count: size_t, size: size_t) -> *mut c_void;
49    pub fn realloc(p: *mut c_void, newsize: size_t) -> *mut c_void;
50    pub fn free(p: *mut c_void);
51    pub fn posix_memalign(ptr: *mut *mut c_void, alignment: size_t, size: size_t) -> c_int;
52    pub fn aligned_alloc(alignment: size_t, size: size_t) -> *mut c_void;
53    pub fn malloc_size(p: *mut c_void) -> size_t;
54    pub fn malloc_usable_size(p: *mut c_void) -> size_t;
55
56}