Skip to content

Commit ed2d012

Browse files
author
Andronik Ordian
committed
libmimalloc-sys: expose mit_usable_size
1 parent c6bf457 commit ed2d012

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

libmimalloc-sys/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extern "C" {
1010
pub fn mi_malloc_aligned(size: usize, alignment: usize) -> *const c_void;
1111
pub fn mi_realloc_aligned(p: *const c_void, size: usize, alignment: usize) -> *const c_void;
1212
pub fn mi_free(p: *const c_void) -> c_void;
13+
pub fn mi_usable_size(p: *mut c_void) -> usize;
1314
}
1415

1516
#[cfg(test)]
@@ -34,4 +35,14 @@ mod tests {
3435
let ptr = unsafe { mi_realloc_aligned(ptr as *const c_void, 8, 8) } as *mut u8;
3536
unsafe { mi_free(ptr as *const c_void) };
3637
}
38+
39+
#[test]
40+
fn it_calculates_usable_size() {
41+
let ptr = unsafe { mi_malloc(32) } as *mut u8;
42+
let usable_size = unsafe { mi_usable_size(ptr as *mut c_void) };
43+
assert!(
44+
usable_size >= 32,
45+
"usable_size should at least equal to the allocated size"
46+
);
47+
}
3748
}

0 commit comments

Comments
 (0)