2 releases

0.1.2 Oct 22, 2022
0.1.1 Oct 22, 2022
0.1.0 Oct 19, 2022

#131 in #memory-allocator

Download history 6/week @ 2024-06-24 1/week @ 2024-07-15 8/week @ 2024-07-29 25/week @ 2024-09-23 42/week @ 2024-09-30

67 downloads per month
Used in 2 crates (via golana-loader)

MIT license

15KB
340 lines

smalloc

A small memory allocator for Solana programs


lib.rs:

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

Usage:

  1. Add this crate as dependency

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

[features]
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")]
#[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.

No runtime deps

Features