Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.

[1]http://github.com/thestinger/rust-core


Rust uses malloc provided by the system. It's mentioned in the article:

"I actually do have a malloc function because my Rust standard library needs to link against it"

He hasn't implemented malloc in his kernel yet (except for a stub).


She actually (Julia Evans)!

I just want to point that out since women don't get enough cred in our field.


Thanks, I'm not sure how I got that wrong. I certainly registered that it was a woman when I read the article.


> Rust uses malloc provided by the system.

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.

[1] http://www.canonware.com/jemalloc/


There was a really terrifying bug and he malloc got removed, wish I could remember the ticket number. Pretty sure it's not back...


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).


there's no relationship between "Jason Evans" and "Julia Evans" =) That's a coincidence.


> Copyright © 2013 Jason Evans

I think you could forgive people for not knowing that Jason and Julia are the same person? (that's what you are implying, right?)


You appear to be falling victim to the vagaries of footnote notation. Blame HN for not giving us Markdown with which to embed links!


As the sibling implied, the "[1]" link is a footnote, referred to from the paragraph mentioning jemalloc. The gender issue was a separate point.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: