|
3 | 3 | use core::ffi::c_void;
|
4 | 4 |
|
5 | 5 | extern "C" {
|
| 6 | + /// Allocate zero-initialized `size` bytes. |
| 7 | + /// |
| 8 | + /// Returns a pointer to newly allocated zero-initialized memory, or null if |
| 9 | + /// out of memory. |
6 | 10 | pub fn mi_zalloc(size: usize) -> *mut c_void;
|
| 11 | + |
| 12 | + /// Allocate `size` bytes. |
| 13 | + /// |
| 14 | + /// Returns pointer to the allocated memory or null if out of memory. |
| 15 | + /// Returns a unique pointer if called with `size` 0. |
7 | 16 | pub fn mi_malloc(size: usize) -> *mut c_void;
|
8 |
| - pub fn mi_realloc(p: *mut c_void, size: usize) -> *mut c_void; |
| 17 | + |
| 18 | + /// Re-allocate memory to `newsize` bytes. |
| 19 | + /// |
| 20 | + /// Return pointer to the allocated memory or null if out of memory. If null |
| 21 | + /// is returned, the pointer `p` is not freed. Otherwise the original |
| 22 | + /// pointer is either freed or returned as the reallocated result (in case |
| 23 | + /// it fits in-place with the new size). |
| 24 | + /// |
| 25 | + /// If `p` is null, it behaves as [`mi_malloc`]. If `newsize` is larger than |
| 26 | + /// the original `size` allocated for `p`, the bytes after `size` are |
| 27 | + /// uninitialized. |
| 28 | + pub fn mi_realloc(p: *mut c_void, newsize: usize) -> *mut c_void; |
| 29 | + |
| 30 | + /// Allocate `size` bytes aligned by `alignment`, initialized to zero. |
| 31 | + /// |
| 32 | + /// Return pointer to the allocated memory or null if out of memory. |
| 33 | + /// |
| 34 | + /// Returns a unique pointer if called with `size` 0. |
9 | 35 | pub fn mi_zalloc_aligned(size: usize, alignment: usize) -> *mut c_void;
|
| 36 | + |
| 37 | + /// Allocate `size` bytes aligned by `alignment`. |
| 38 | + /// |
| 39 | + /// Return pointer to the allocated memory or null if out of memory. |
| 40 | + /// |
| 41 | + /// Returns a unique pointer if called with `size` 0. |
10 | 42 | pub fn mi_malloc_aligned(size: usize, alignment: usize) -> *mut c_void;
|
11 |
| - pub fn mi_realloc_aligned(p: *mut c_void, size: usize, alignment: usize) -> *mut c_void; |
| 43 | + |
| 44 | + /// Re-allocate memory to `newsize` bytes, aligned by `alignment`. |
| 45 | + /// |
| 46 | + /// Return pointer to the allocated memory or null if out of memory. If null |
| 47 | + /// is returned, the pointer `p` is not freed. Otherwise the original |
| 48 | + /// pointer is either freed or returned as the reallocated result (in case |
| 49 | + /// it fits in-place with the new size). |
| 50 | + /// |
| 51 | + /// If `p` is null, it behaves as [`mi_malloc_aligned`]. If `newsize` is |
| 52 | + /// larger than the original `size` allocated for `p`, the bytes after |
| 53 | + /// `size` are uninitialized. |
| 54 | + pub fn mi_realloc_aligned(p: *mut c_void, newsize: usize, alignment: usize) -> *mut c_void; |
| 55 | + |
| 56 | + /// Free previously allocated memory. |
| 57 | + /// |
| 58 | + /// The pointer `p` must have been allocated before (or be null). |
12 | 59 | pub fn mi_free(p: *mut c_void);
|
| 60 | + |
| 61 | + /// Return the available bytes in a memory block. |
| 62 | + /// |
| 63 | + /// The returned size can be used to call [`mi_expand`] successfully. |
13 | 64 | pub fn mi_usable_size(p: *mut c_void) -> usize;
|
14 | 65 | }
|
15 | 66 |
|
|
0 commit comments