https://github.com/bra1l0r/palloc
Portable linked-list allocator designed for baremetal systems
https://github.com/bra1l0r/palloc
allocator no-std rust
Last synced: about 2 months ago
JSON representation
Portable linked-list allocator designed for baremetal systems
- Host: GitHub
- URL: https://github.com/bra1l0r/palloc
- Owner: BRA1L0R
- License: mit
- Created: 2021-11-08T17:08:01.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-11-11T17:09:58.000Z (over 3 years ago)
- Last Synced: 2025-03-24T15:13:41.503Z (2 months ago)
- Topics: allocator, no-std, rust
- Language: Rust
- Homepage: https://crates.io/crates/palloc
- Size: 35.2 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Palloc
Portable linked-list allocator for embedded / baremetal systems.
### Using the crate
Include this in the `[dependencies]` section of `Cargo.toml`
```
palloc = "0.1.0"
```This crate uses **unstable features** of Rust, so it requires the `nightly` update channel. Update the toolchain
for your project folder with:```
rustup override set nightly
```### Crate features
- `spin` (default): provides a GlobalAllocator implementation using a [spin lock](https://crates.io/crates/spin).
- `allocator_api` (default): enables the Allocator trait and implements it on all global allocators.### Example
```rust
#![no_std]use core::ptr::NonNull;
use palloc::{GlobalPalloc, SpinPalloc};// the allocator is initialized using a const empty function, but it is
// not ready yet, we must initialize it first in main.
#[global_allocator]
static mut ALLOCATOR: SpinPalloc = SpinPalloc::empty();fn main() {
// First of all we must define the bounds of our heap. Check
// Palloc or GlobalPalloc documentation for informations.// Heap starting address
let heap_start = 0x8000 as *mut u8;
// Heap size
let heap_size = 0xF000;// accessing statics is an unsafe operation
// so it must be sorrounded by an unsafe block
unsafe { ALLOCATOR.init(NonNull::new(heap_start).unwrap(), heap_size) };// we can now use the heap!
// ...
}
```### Documentation
Everything you need to know is already written in the rustdocs.
Click on the badge under the readme's title or [click here](https://docs.rs/palloc) to read the full
documentation.