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