Skip to content
General purpose global Rust allocator(s) with static storage.
Branch: master
Clone or download
HeroicKatora Refactor allocation logic
Bumping the consumed counter was moved into a separate method to make
tracking of counter monotonicity easier. Trying to allocate space from
this counter is moved into a method so that it can be reused for
fallible operations on layouts as well.
Latest commit 3a588ef Jul 20, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Refactor allocation logic Jul 20, 2019
tests Handle zst types for allocation Jul 20, 2019
.cirrus.yml Add planned cirrus CI integration Jul 10, 2019
.gitignore Initial files as sketched in a play.rust-lang.org Jul 10, 2019
Cargo.lock Release next version Jul 20, 2019
Cargo.toml Release next version Jul 20, 2019
Changes.md Release next version Jul 20, 2019
LICENSE Add metafiles Jul 10, 2019
Readme.md Release next version Jul 20, 2019

Readme.md

static-alloc

General purpose global allocator(s) with static storage.

Goal and Target Platform

Provides an allocator for extremely resource constrained environments where the only memory guaranteed is your program's image in memory as provided by the loader. Possible use cases are OS-less development, embedded, bootloaders (even stage0/1 maybe, totally untested). The primary goals are minimalism, simplicity, and correctness.

This library is far from complete, and contributions with bug fixes or more allocators are welcome. As a general principle those should provide mechanisms, not policy, have a usable direct api that does not require them to be registered as the single global allocator.

Feature requests and 'help' issues will be closed, drafts will be decided on the spot. With simplicity in mind, ideas that can not be put into a draft form are likely too complex anyways. PRs should be extremely reluctant with introducing new dependencies and should contain no non-optional dependency.

Usage

use static_alloc::Slab;

#[global_allocator]
static A: Slab<[u8; 1 << 16]> = Slab::uninit();

fn main() {
    // Vec occupying `1 << 9` bytes
    let v = vec![0xdeadbeef_u32; 128];

    // Can also allocate values directly. Even without `alloc::vec::Vec`.
    let buffer: &'static mut [u32; 128] = A.leak([0; 128])
    	.unwrap_or_else(|_| panic!("Runtime allocated too much before main"));
    buffer.copy_from_slice(&v);

    println!("{:x?}", &buffer[..]);
}

Additional

Crates.io Status Docs.rs Status License CI Status

This project is mainly MIT licensed. You may alternatively choose the Unlicense instead in which case the copyright headers signify the parts dedicated to the public domain to the fullest possible extent instead.

You can’t perform that action at this time.