4 ms·
This is a strange distinction. So something is garbage because it is not used? In Rust, a Vec is only deallocated at the end of the function, regardless of when
by anon-3988 2y ago
This is a strange distinction. So something is garbage because it is not used? In Rust, a Vec is only deallocated at the end of the function, regardless of when it is actually stopped being used. Are those garbage too?
At this point, garbage just means whatever does not follow RAII. And RAII is not the best solution either. For throughput reasons, GC languages can be siginificantly faster exactly because it doesn't have to clean those "garbage" at every step.
- VWWHFSfQ 2y ago> GC languages can be siginificantly faster exactly because it doesn't have to clean those "garbage" at every step. Which GC languages are significantly faster than Rust and C++?
- hot_gril 2y agoIt can happen in practice. For example, I see a lot of C++ code with extra string copying that would be hard to avoid. Like if some func takes a const vector<string>& and you have a string in any structure besides a vector, you're gonna copy that string.
- hot_gril 2y ago(of course Java's pointers-everywhere approach has downsides and is generally slower, but there are scenarios where this works to your advantage)
- VWWHFSfQ 2y agoSo a theoretical GC language can hypothetically be faster than Rust or C++. Which language? Does one exist?
- hot_gril 2y agoIt'd be Golang if anything. Java might have too much overhead to be faster than C++ without negligence, but that's not because of the GC.
- maattdd 2y agoYou can avoid this with custom allocator in C++ for example, you don't have to actually do memory work at synchronous time (aka in destructor)
- philippta 2y agoThanks, this exactly my point.