shared memory and loading savings
shared memory and loading savings
Posted Jan 31, 2025 19:38 UTC (Fri) by pizza (subscriber, #46)In reply to: shared memory and loading savings by mb
Parent article: Vendoring Go packages by default in Fedora
Rust-the-language may be used, but most existing Rust code (including most crates) won't be useful on targets that limited.
Posted Jan 31, 2025 20:34 UTC (Fri)
by Cyberax (✭ supporter ✭, #52523)
[Link] (2 responses)
A lot of crates like serde that are not affected at all.
Posted Jan 31, 2025 21:47 UTC (Fri)
by excors (subscriber, #95769)
[Link] (1 responses)
When you're trying to strictly limit stack usage, I'm not sure Rust is a good fit - something simple like assigning to a static struct will conceputally construct a temporary value on the stack then memcpy it into the static, and you're relying on the optimiser to turn that into direct writes to the static's memory, and sometimes the optimiser won't cooperate and you'll overflow your tiny stack.
If I remember correctly, I tried this a while ago and it stopped optimising away the stack allocation when the struct size exceeded maybe 8KB. If you neatly contain all your application state in one big struct that's more than half your RAM, and try to dynamically initialise it, that's a problem. You have to write ugly, unidiomatic code and then hope the optimiser cooperates. It's easier to avoid implicit stack allocations in C, and in such a small program with no dynamic allocation and no threading you don't need the memory safety benefits of Rust, so it doesn't seem a good tradeoff.
(By the time you get up to, say, 256KB of RAM, you're not going to be accounting so carefully for every byte and you'll probably have a real heap and an RTOS, and then I think the tradeoff flips the other way and Rust is much more appropriate.)
Posted Jan 31, 2025 21:57 UTC (Fri)
by mb (subscriber, #50428)
[Link]
As I said.
>something simple like assigning to a static struct
Assigning to a static struct is not simple. Neither in C nor in Rust.
shared memory and loading savings
shared memory and loading savings
shared memory and loading savings
128 bytes RAM total work just fine.
This is what actually works in real life.
But anyway, it has to grow *much* larger than anything possible with 128 bytes of RAM to become a memcpy problem.
I have seen this problem with multi-megabyte ESP32. And then the solution is just to use heap allocation. Which is not a real problem on ESP32.