4 ms·
The number of cases where i have to use a generic memory allocator like malloc in a typical project are extremely rare, so no. I never said that const is like
by dreta 10y ago
The number of cases where i have to use a generic memory allocator like malloc in a typical project are extremely rare, so no.
I never said that const is like anything, i just used it as an example.
- dbaupp 10y agoOne can get all of the problems mentioned with allocators other than malloc, up to and including using only the stack. Also, sure the implementation of another allocator might use a smattering of `unsafe`, but I'm guess that it will be less than you probably expect: one of Rust's biggest is strengths is the ability to build safe interfaces for things without performance cost. One can see an example for this in http://os.phil-opp.com/ http://os.phil-opp.com/ where the author is slowly describing creating an operating system, all while concentrating on how to exploit Rust features to let the compiler help the programmer, such as http://os.phil-opp.com/modifying-page-tables.html http://os.phil-opp.com/modifying-page-tables.html .
- Retra 10y agoWhat does malloc have to do with anything? Returning a pointer to the stack is just as likely to break everything if done improperly. Moving or copying a struct that points at itself is also going to break. In fact, "how to to either of these things" is such a common question for new rust programmers trying to solve their borrow checker complaints that it constitutes pretty good evidence people are doing these things all the time with little understanding of why they are problematic. And even if you _do_ know better, circumventing the borrow checker is fairly trivial.
- vardump 10y ago>Returning a pointer to the stack is just as likely to break everything if done improperly. How's returning a pointer to stack ever safe?