2023-03-16 18:07:58 +00:00
|
|
|
# `buddy_system_allocator`
|
|
|
|
|
2024-12-13 04:33:58 -05:00
|
|
|
[`buddy_system_allocator`][1] is a crate implementing a basic buddy system
|
|
|
|
allocator. It can be used both for [`LockedHeap`][2] implementing
|
2023-12-31 00:15:07 +01:00
|
|
|
[`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:
|
|
|
|
|
2023-10-11 11:32:12 +02:00
|
|
|
<!-- mdbook-xgettext: skip -->
|
2023-12-31 00:15:07 +01:00
|
|
|
|
2023-03-16 18:07:58 +00:00
|
|
|
```rust,editable,compile_fail
|
|
|
|
{{#include allocator-example/src/main.rs:main}}
|
|
|
|
```
|
|
|
|
|
|
|
|
<details>
|
|
|
|
|
2023-12-31 00:15:07 +01:00
|
|
|
- PCI BARs always have alignment equal to their size.
|
|
|
|
- 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
|