memapi_mimalloc_sys/
lib.rs

1#![no_std]
2
3// TODO: make sure this is up to date with the latest mimalloc, not the rather old fork from normal mimalloc_rust
4
5use core::ffi::c_void;
6
7extern crate libc;
8
9#[cfg(feature = "extended")]
10mod extended;
11#[cfg(feature = "extended")]
12pub use extended::*;
13
14extern "C" {
15    /// Allocate zero-initialized `size` bytes.
16    ///
17    /// Returns a pointer to newly allocated zero-initialized memory, or null if out of memory.
18    pub fn mi_zalloc(size: usize) -> *mut c_void;
19
20    /// Allocate `size` uninitialized bytes.
21    ///
22    /// Returns a pointer to the allocated memory or null if out of memory. The pointer will still
23    /// be unique if `size` is 0.
24    pub fn mi_malloc(size: usize) -> *mut c_void;
25
26    /// Reallocates memory to `new_size` bytes.
27    ///
28    /// Returns a pointer to the allocated memory or null if out of memory.
29    ///
30    /// If null is returned, the pointer `p` is not freed. Otherwise, the original pointer is either
31    /// freed or returned as the result if the reallocation fits in-place with the new size.
32    ///
33    /// If `p` is null, this is equivalent to [`mi_malloc`]. If `new_size` is larger than the
34    /// original `size` allocated for `p`, the bytes after `size` are uninitialized.
35    pub fn mi_realloc(p: *mut c_void, new_size: usize) -> *mut c_void;
36
37    /// Allocate `size` zeroed bytes with an alignment of `align`, initialized to zero.
38    ///
39    /// Returns a pointer to the allocated memory or null if out of memory. The pointer will still
40    /// be unique if `size` is 0.`
41    pub fn mi_zalloc_aligned(size: usize, align: usize) -> *mut c_void;
42
43    /// Allocate `size` uninitialized bytes with an alignment of `align`.
44    ///
45    /// Returns a pointer to the allocated memory or null if out of memory. The pointer will still
46    /// be unique if `size` is 0.`
47    pub fn mi_malloc_aligned(size: usize, align: usize) -> *mut c_void;
48
49    /// Re-allocate memory to a size of `new_size` bytes, with an alignment of `align`.
50    ///
51    /// Returns a pointer to the allocated memory or null if out of memory.
52    ///
53    /// If null is returned, the pointer `p` is not freed. Otherwise, the original pointer is either
54    /// freed or returned as the result if the reallocation fits in-place with the new size.
55    ///
56    /// If `p` is null, this is equivalent to [`mi_malloc_aligned`]. If `new_size` is
57    /// larger than the original `size` allocated for `p`, the bytes after `size` are uninitialized.
58    pub fn mi_realloc_aligned(p: *mut c_void, new_size: usize, align: usize) -> *mut c_void;
59
60    /// Deallocates previously allocated memory.
61    ///
62    /// The pointer `p` must have been allocated before or be null.
63    pub fn mi_free(p: *mut c_void);
64}