mmtk/util/malloc/
library.rs1#[cfg(feature = "malloc_jemalloc")]
4pub use self::jemalloc::*;
5#[cfg(not(any(feature = "malloc_jemalloc", feature = "malloc_mimalloc",)))]
6pub use self::libc_malloc::*;
7#[cfg(feature = "malloc_mimalloc")]
8pub use self::mimalloc::*;
9
10pub const BYTES_IN_MALLOC_PAGE: usize = 1 << LOG_BYTES_IN_MALLOC_PAGE;
14
15#[cfg(feature = "malloc_jemalloc")]
20mod jemalloc {
21 pub const LOG_BYTES_IN_MALLOC_PAGE: u8 = crate::util::constants::LOG_BYTES_IN_PAGE;
23 pub use jemalloc_sys::{calloc, free, malloc, realloc};
25 pub use jemalloc_sys::posix_memalign;
27 pub use jemalloc_sys::malloc_usable_size;
29}
30
31#[cfg(feature = "malloc_mimalloc")]
32mod mimalloc {
33 pub const LOG_BYTES_IN_MALLOC_PAGE: u8 = crate::util::constants::LOG_BYTES_IN_PAGE;
35 pub use mimalloc_sys::{
37 mi_calloc as calloc, mi_free as free, mi_malloc as malloc, mi_realloc as realloc,
38 };
39 pub use mimalloc_sys::mi_posix_memalign as posix_memalign;
41 pub use mimalloc_sys::mi_malloc_usable_size as malloc_usable_size;
43}
44
45#[cfg(not(any(feature = "malloc_jemalloc", feature = "malloc_mimalloc",)))]
47mod libc_malloc {
48 pub const LOG_BYTES_IN_MALLOC_PAGE: u8 = crate::util::constants::LOG_BYTES_IN_PAGE;
50 pub use libc::{calloc, free, malloc, realloc};
52 pub use libc::posix_memalign;
54 #[cfg(target_os = "linux")]
56 pub use libc::malloc_usable_size;
57 #[cfg(target_os = "macos")]
58 extern "C" {
59 pub fn malloc_size(ptr: *const libc::c_void) -> usize;
60 }
61 #[cfg(target_os = "macos")]
62 pub use self::malloc_size as malloc_usable_size;
63}