macro_rules! custom_heap_default {
() => { ... };
}Expand description
Define the default global allocator.
The default global allocator is enabled only if the calling crate has not disabled it using Cargo features as described below. It is only defined for on-chain targets.
§Cargo features
A crate that calls this macro can provide its own custom heap
implementation, or allow others to provide their own custom heap
implementation, by adding a custom-heap feature to its Cargo.toml. After
enabling the feature, one may define their own global allocator in the
standard way.
§RISC-V heap base
On the RISC-V target the heap base is supplied by the loader at runtime, not fixed at
compile time. The entrypoint! and entrypoint_no_alloc! macros record it (via
allocator::set_heap_base) before any allocation runs. If you install this allocator
behind a hand-rolled entrypoint instead of those macros, you must call both set_heap_base
and set_heap_limit at the very start of the entrypoint. Omitting set_heap_base leaves the
heap at address 0, so the first allocation hits unmapped memory and traps; omitting
set_heap_limit leaves the limit at 0, so the allocator refuses every allocation (null →
handle_alloc_error → abort).