5 ms·
I'm an embedded Rust developer, and was a little confused by this paper until I noticed it was written in 2015. There are now solutions to a number of the probl
by bascule 9y ago
I'm an embedded Rust developer, and was a little confused by this paper until I noticed it was written in 2015. There are now solutions to a number of the problems they pose both at the language level and the library level:
Here's one in particular:
In principal, this would allow us to statically allocate
a buffer sized for each particular closure.
Unfortunately, there is no size_of keyword in Rust,
and static initialization cannot invoke functions—
in this case the function size_of<T>() -> usize provided
by the Rust core library.
This can be solved by using the lazy_static crate:
https://github.com/rust-lang-nursery/lazy-static.rs https://github.com/rust-lang-nursery/lazy-static.rs
From the description in the README:
Using this macro, it is possible to have statics that
require code to be executed at runtime in order to be
initialized.
Hey look, it's exactly what they need! It's also "no_std" compatible and can work just fine in a kernel-like context.
Take this paper with a grain of salt: it's a bit dated at this point, and there are solutions for a number of the problems posed.
- codys 9y agoNote that lazy-static does not "statically allocate a buffer" for all definitions of "statically allocate": lazy-static computes it's value on first use, and must use dynamic alloc space (ie: malloc/box) Also, lazy-static has been around for a long time. Releases first occurred in 2014! I'd be surprised if it had not been considered.
- bascule 9y agoWell, their original stated problem was just invoking size_of() at runtime, which lazy-static solves. That said, Rust supports custom allocators now: https://doc.rust-lang.org/book/custom-allocators.html https://doc.rust-lang.org/book/custom-allocators.html Write your own allocator and use Box.
- rkangel 9y agoI think you misunderstand what 'statically allocate' means. That means a size known at compile time, so that the space for that variable can be assigned in the memory map of the executable. Anything involving a 'custom allocator' is doing runtime memory allocation.
- kibwen 9y ago> Releases first occurred in 2014! I'd be surprised if it had not been considered. I wouldn't be surprised if it hadn't been considered. The paper was released in 2015, so development may have begun in 2014. Furthermore, I don't believe the authors were engaged with the broader Rust community before this paper was released (they are today), so it's possible that there was no expert there to advise them about this approach. Also, discoverability of libraries was more of an issue back then, so it's plausible that they wouldn't have found it independently.
- turbinerneiter 9y agoI'm looking to try embedded Rust right this weekend. What Hardware are you using?
- bascule 9y agoI develop for Hardware Security Modules, which is probably a bit different than your typical embedded use case.
- steveklabnik 9y agoIt seems like many people (including the authors of this paper) do work on various Cortex M boards. Make sure to check out "japaric" on GitHub; they have built a lot of awesome tooling for Rust embedded stuff.
- SilasX 9y agoIs there a solution to commenters who think monospace quoting on HN is legible on mobile? Edit: I apologize for the snark, but still, monospace for quoting doesn't add anything, and I don't see why people do it once they see it forces a side scroll on small screens. Please just use >
- bronson 9y agoHave you tried your suggestion? How do you use > for more than one line? > because HN formats > text blocks > like this
- jacobolus 9y agoIn my opinion the best way to quote here is to start each paragraph with a leading > and then italicize the whole quotation with asterisks around each paragraph. > It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way – in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only.
- SilasX 9y agoYou put > at the beginning of each paragraph in the excerpt to indicate that it's part of the quotation. It's easy to see at a glance that a given paragraph is part of the quote.
- stymaar 9y agoJust add a newline inbetween : > like > this