pub fn fixed_bytes(current_size_bytes: usize, add_bytes: usize) -> NonZeroUsize
Expand description
Memory map resize by a fixed amount of bytes.
§Method
This function will current_size_bytes + add_bytes
and then round up to nearest OS page size.
let page_size: usize = PAGE_SIZE.get();
// Anything below the page size will round up to the page size.
for i in 0..=page_size {
assert_eq!(fixed_bytes(0, i).get(), page_size);
}
// (page_size + 1) will round up to (page_size * 2).
assert_eq!(fixed_bytes(page_size, 1).get(), page_size * 2);
// (page_size + page_size) doesn't require any rounding.
assert_eq!(fixed_bytes(page_size, page_size).get(), page_size * 2);
§Panics
This function will panic if adding onto current_size_bytes
overflows usize::MAX
.
ⓘ
// Ridiculous large numbers panic.
fixed_bytes(1, usize::MAX);