1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-26 17:23:01 +02:00
comprehensive-rust/src/bare-metal/useful-crates/buddy_system_allocator.md

24 lines
923 B
Markdown
Raw Normal View History

2023-03-16 18:07:58 +00:00
# `buddy_system_allocator`
[`buddy_system_allocator`][1] is a third-party crate implementing a basic buddy system allocator.
It can be used both for [`LockedHeap`][2] implementing [`GlobalAlloc`][3] so you can use the
standard `alloc` crate (as we saw [before][4]), or for allocating other address space. For example,
we might want to allocate MMIO space for PCI BARs:
```rust,editable,compile_fail
{{#include allocator-example/src/main.rs:main}}
```
<details>
* PCI BARs always have alignment equal to their size.
2023-04-05 14:15:37 +01:00
* Run the example with `cargo run` under `src/bare-metal/useful-crates/allocator-example/`. (It won't
run in the Playground because of the crate dependency.)
2023-03-16 18:07:58 +00:00
</details>
[1]: https://crates.io/crates/buddy_system_allocator
[2]: https://docs.rs/buddy_system_allocator/0.9.0/buddy_system_allocator/struct.LockedHeap.html
[3]: https://doc.rust-lang.org/core/alloc/trait.GlobalAlloc.html
[4]: ../alloc.md