Re:How to make sure no Dynamic Memory is used
by 3a2d29 on Monday November 07, 2022 @06:37PM
(#33514100)
Doesn’t the compiler do some hidden allocations?
And as a follow up, why use rust if allocations mean ownership rules are no longer needed?
Re:How to make sure no Dynamic Memory is used
by SAI_Peregrinus on Monday November 07, 2022 @07:29PM
(#33514521)
Rust with no_std (and without the Alloc crate) won't do any hidden heap allocations. There's no allocator at all in such an environment! There is still a stack, and there are still static allocations. And of course you can still allocate statically in your linker script.
Ownership still matters, because nothing about ownership cares about heap allocation vs stack allocation.
Re:How to make sure no Dynamic Memory is used
by abraxas on Monday November 07, 2022 @09:00PM
(#33515110)
Thanks for clarifying this. My dabbling in Rust a few years ago ended when I could not find a satisfying answer to the question "how do I prevent any unwanted dynamic allocations in this language?". At the time I found no good answers and gave up on trying to learn the language as that was not the kind of thing I was willing to relinquish to the wisdom of the compiler.
Re:How to make sure no Dynamic Memory is used
by kazinator on Monday November 07, 2022 @10:20PM
(#33515552)
What if the embedded system's library bundles the allocator with needed routines?
Or Rust just provides all that for every known system, so you're OK?
Re:How to make sure no Dynamic Memory is used
by sarahsbasar on Tuesday November 08, 2022 @02:28AM
(#33516766)
And in C you use -ffreestanding/nostdlib
The problem was how to make sure 3rd party libraries don't allocate.
In Rust, you just use no_std for small embedded work.