Re-exported from alloc::heap.
Raw heap allocation and checked size arithmetic.
Types
AllocError | Allocation failure, as a value. |
Storage | The fallible allocation primitives, as static methods. |
HeapAllocator | Static allocator methods backed by the host heap. |
Uninit! | Sole ownership of one uninitialized heap block: its base address and its extent. |
Functions
checked_add | a + b, or abort if the sum is not representable. |
checked_mul | a * b, or abort if the product is not representable. |
at_least_one | The size of the block to ask malloc or realloc for: size, or one byte for none. |
Function declarations
fn checked_addsource
fn checked_add(a: usize, b: usize) -> usize { ... }
a + b, or abort if the sum is not representable.
Checked by subtraction before adding: usize::MAX - b cannot wrap, so a > usize::MAX - b detects overflow before a wrapped (too small) size could reach malloc. alloc::arena::has_room uses the same idiom.
fn checked_mulsource
fn checked_mul(a: usize, b: usize) -> usize { ... }
a * b, or abort if the product is not representable.
Guarded by division against usize::MAX, for the same reason: testing a * b / b != a would inspect an already-wrapped value. b == 0usize is special-cased because the guard divides by it; a zero-sized element or a zero-element request is legitimate and cannot overflow.
fn at_least_onesource
fn at_least_one(size: usize) -> usize { ... }
The size of the block to ask malloc or realloc for: size, or one byte for none.