2个版本

0.1.2 2022年10月22日
0.1.1 2022年10月22日
0.1.0 2022年10月19日

#101 in #alloc


2个crate中使用(通过golana-loader

MIT授权

15KB
340

smalloc

适用于Solana程序的轻量级内存分配器


lib.rs:

Smalloc是Solana程序的一个小巧且简单的内存分配器。

使用方法

  1. 将此crate作为依赖项添加

  2. 在Cargo.toml中添加一个名为"custom-heap"的虚特征

[features]
default = ["custom-heap"]
custom-heap = []
  1. 在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();

注意:"dynamic_start"特征用于单元测试。

无运行时依赖

特性