Expand description

Smalloc is a small and simple memory allocator for Solana programs.


  1. Add this crate as dependency

  2. Add a dummy feature called “custom-heap” in Cargo.toml:

default = ["custom-heap"]
custom-heap = []
  1. 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")]
static ALLOC: Smalloc<{ HEAP_START_ADDRESS as usize }, { HEAP_LENGTH as usize }, 16, 1024> =

Note: The “dynamic_start” feature is for unit tests.