Does Rust not have dynamic heap allocation (malloc)? An explanation to accompany the article would be nice. Or at least a comprehensive response to my comment ;-)
Rust, and virtually every other programming language out there, like C++, D, python, C#, etc. have a runtime library built to aid the programmer. When programming an operating system, you must implement the runtime that the language expects if you wish to use some features of that language. In the case of Rust that would be dynamic heap allocation. The C++ "new" and "delete" operators (analogous to C's malloc() and free() ) are also an example of a runtime that must be implemented for those operators to be used. Python and C# have gigantic runtimes (the interpreter/JIT compiler).
Rust does have dynamic heap allocation. I'm writing freestanding Rust (using #[no_std]). This means that I can compile Rust code without using the normal standard library, and makes it possible to do things like write a kernel in Rust (which is my use case right now).
There's a support library for writing freestanding / embedded Rust called rust-core [1]. This library requires that you define a malloc function: it declares
extern {
pub fn malloc(size: uint) -> *mut u8;
}
However, it doesn't require that the malloc implementation be more than a stub, and as long as I don't allocate memory at any point that works fine.
It doesn't lock you into the system allocator. You can LD_PRELOAD your own, and in the past Rust has even shipped with and used jemalloc[1] (though I believe it's not using it at the moment). Furthermore, as alluded to at the end of the article, you can override the compiler's malloc implementation via what Rust calls "lang items" (which are sadly ill-documented).
> He hasn't implemented malloc in his kernel yet (except for a stub).
Rather, Julia hasn't implemented malloc in her kernel yet.
The first time that jemalloc got removed was because our red zones were simply too small for it to work. The second time that it got removed was because somehow Rust was using jemalloc to allocate some memory and, once in a while, an entirely different allocator to free that memory (this is likely the terrifying bug that you remember).