
Writing an OS in Rust: Heap Allocation - phil-opp
https://os.phil-opp.com/heap-allocation/
======
Ericson2314
Phill's blog series is the best there is for kernel Rust. Glad to see another
installment!

Note that in Rust today we can only use standard collection with the global
allocator. [https://github.com/phil-
opp/blog_os/blob/post-10/src/main.rs...](https://github.com/phil-
opp/blog_os/blob/post-10/src/main.rs#L26) in the blog post it is intialized,
and there's nothing to prevent allocation earlier and that will fail.

But there is work in progress (first [https://github.com/rust-
lang/rust/pull/58457](https://github.com/rust-lang/rust/pull/58457)) that will
allow using local allocators, removing the ambient authority that makes that
failure possible. Note that this doesn't mean a runtime cost. One can pass
around a zero-sized token that is completely erased.

~~~
phil-opp
Thanks so much!

Yes, I'm eagerly awaiting [https://github.com/rust-
lang/rust/pull/58457](https://github.com/rust-lang/rust/pull/58457) and your
follow-up [https://github.com/rust-
lang/rust/pull/60703](https://github.com/rust-lang/rust/pull/60703). AFAIK, a
global allocator is still required with them (so we still have to initialize
it), but it allows us to choose a different allocator for some collections,
e.g. to avoid deadlocks in interrupt handlers.

