Skip to content

Commit d5ff7e5

Browse files
Thom Chiovolonithomcc
authored andcommitted
Add documentation for current functions in libmimalloc-sys
1 parent d604cb6 commit d5ff7e5

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

libmimalloc-sys/src/lib.rs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,64 @@
33
use core::ffi::c_void;
44

55
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.
610
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.
716
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.
935
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.
1042
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).
1259
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.
1364
pub fn mi_usable_size(p: *mut c_void) -> usize;
1465
}
1566

0 commit comments

Comments
 (0)