5 ms·
I slightly disagree. Using heap allocated types is perfectly fine. The biggest thing I have to keep reminding myself coming from higher level languages is to re
by ZephyrBlu 4y ago
I slightly disagree. Using heap allocated types is perfectly fine. The biggest thing I have to keep reminding myself coming from higher level languages is to re-use data structures, and to architect things in a way that this is possible.
Allocating a new String/Vec every single time you do something is killer for performance, but if you do it once up front then clear the data structure for the next use it should be performant enough.
- criddell 4y ago> re-use data structures That's funny. I've been going mostly the other direction. I'm avoiding mutable structures whenever possible. I have a much easier time reasoning about stuff when I know that things aren't going to change mid-life.
- galangalalgol 4y agoThat is certainly true, but if you are talking about things that are too big to stack allocate, the cognitive overhead of reusing heap allocated items is the price for getting back the throughput overhead of memory allocation.
- ZephyrBlu 4y agoI don't know what you're programming, but it's pretty hard to not use more complex structures like Vecs and HashMaps without them being mutable. Also, that is exactly what Rust's borrow-checker is there for. It doesn't allow you to mutably borrow the same data structure multiple times.
- criddell 4y agoI was thinking more about the things being contained rather than the containers themselves. But you're right - they are all data structures.