Skip to content

Commit 099dbdc

Browse files
committed
Add a short usage section to Readme
1 parent 49d98d1 commit 099dbdc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,29 @@
44

55
[Documentation](http://phil-opp.github.io/linked-list-allocator/linked_list_allocator/index.html)
66

7+
## Usage
8+
9+
Create a static allocator in your root module:
10+
11+
```rust
12+
use linked_list_allocator::LockedHeap;
13+
14+
#[global_allocator]
15+
static ALLOCATOR: LockedHeap = LockedHeap::empty();
16+
```
17+
18+
Before using this allocator, you need to init it:
19+
20+
```rust
21+
pub fn init_heap() {
22+
let heap_start = …;
23+
let heap_end = …;
24+
let heap_size = heap_end - heap_start;
25+
unsafe {
26+
ALLOCATOR.lock().init(heap_start, heap_size);
27+
}
28+
}
29+
```
30+
731
## License
832
This crate is dual-licensed under MIT or the Apache License (Version 2.0). See LICENSE-APACHE and LICENSE-MIT for details.

0 commit comments

Comments
 (0)