4 ms·
You do have to think about memory a little bit in Rust with RAII, but not much. There are two situations: First there are cyclic data structures. For these yo
by api 3y ago
You do have to think about memory a little bit in Rust with RAII, but not much.
There are two situations:
First there are cyclic data structures. For these you have to be sure to use a construct like weak reference counting pointers for things that are self referential or you will leak memory. Either that or you store links by object ID instead of pointer. The former adds a bit of cognitive overhead and the latter adds runtime overhead.
The second case is high performance code where you want to avoid allocating memory in an inner loop.
The second case comes up a bit in GC languages too though, since if you allocate without thinking you can easily write code that balloons the heap and forces the garbage collector to constantly invoke and do a lot of work to collect temporary objects. The code will work but will be slow and allocate more heap than needed.
Edit: actually embedded is a third situation where you might have to think a lot but that’s true for any language you are using.