Expand description
Smalloc is a small and simple memory allocator for Solana programs.
Usage:
-
Add this crate as dependency
-
Add a dummy feature called “custom-heap” in Cargo.toml:
[features]
default = ["custom-heap"]
custom-heap = []
- Put this in your entrypoint.rs
// START: Heap start
// LENGTH: Heap length
// MIN: Minimal allocation size
// PAGE_SIZE: Allocation page size
#[cfg(target_os = "solana")]
#[global_allocator]
static ALLOC: Smalloc<{ HEAP_START_ADDRESS as usize }, { HEAP_LENGTH as usize }, 16, 1024> =
Smalloc::new();
Note: The “dynamic_start” feature is for unit tests.