1# buddy_system_allocator 2 3[![Crates.io version][crate-img]][crate] 4[![docs.rs][docs-img]][docs] 5 6An (almost) drop-in replacement for [phil-opp/linked-list-allocator](https://github.com/phil-opp/linked-list-allocator). But it uses buddy system instead. 7 8## Usage 9 10To use buddy_system_allocator for global allocator: 11 12```rust 13use buddy_system_allocator::LockedHeap; 14 15#[global_allocator] 16static HEAP_ALLOCATOR: LockedHeap = LockedHeap::<32>::empty(); 17``` 18 19To init the allocator: 20 21```rust 22unsafe { 23 HEAP_ALLOCATOR.lock().init(heap_start, heap_size); 24 // or 25 HEAP_ALLOCATOR.lock().add_to_heap(heap_start, heap_end); 26} 27``` 28 29You can also use `FrameAllocator` and `LockedHeapWithRescue`, see their documentation for usage. 30 31## Features 32 33- **`use_spin`** (default): Provide a `LockedHeap` type that implements the [`GlobalAlloc`] trait by using a spinlock. 34- **`const_fn`** (nightly only): Provide const fn version of `LockedHeapWithRescue::new`. 35 36[`GlobalAlloc`]: https://doc.rust-lang.org/nightly/core/alloc/trait.GlobalAlloc.html 37 38## License 39 40Some code comes from phil-opp's linked-list-allocator. 41 42Licensed under MIT License. Thanks phill-opp's linked-list-allocator for inspirations and interface. 43 44[crate-img]: https://img.shields.io/crates/v/buddy_system_allocator.svg 45[crate]: https://crates.io/crates/buddy_system_allocator 46[docs-img]: https://docs.rs/buddy_system_allocator/badge.svg 47[docs]: https://docs.rs/buddy_system_allocator 48