#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MemoryStats {
pub active: usize,
pub peak: usize,
pub active_with_mapped: usize,
pub peak_with_mapped: usize,
pub cache: usize,
pub memory_limit: usize,
pub cache_limit: usize,
pub system_allocations: u64,
pub wired_limit: usize,
pub wired: usize,
pub mapped: usize,
pub wired_mapped: usize,
}
const PAGE: usize = 16 * 1024;
const SMALL: usize = 256;
pub fn allocation_size(len: usize) -> Option<usize> {
match len {
n if n > PAGE => n.checked_next_multiple_of(PAGE),
n => Some(n.div_ceil(SMALL) * SMALL),
}
}
pub fn mapping_size(len: usize) -> usize {
len.div_ceil(page()) * page()
}
pub(crate) fn page() -> usize {
#[cfg(target_os = "macos")]
{
let page = unsafe { libc::sysconf(libc::_SC_PAGESIZE) };
usize::try_from(page).unwrap_or(PAGE)
}
#[cfg(not(target_os = "macos"))]
PAGE
}