4 ms·
I think the point was more that allocations are fairly explicit. There are a few places in C++ where allocation can happen pretty much invisibly. A copy const
by cogman10 6y ago
I think the point was more that allocations are fairly explicit.
There are a few places in C++ where allocation can happen pretty much invisibly. A copy constructor is an example of that. You might see a new allocation simply by calling a method.
With rust, you usually won't see an allocation unless it is explicitly called for. You can follow the call tree and very easily pick out when those allocations are happening.
- pjmlp 6y agoRust also has operator overloading and implicit conversations, both can cause memory allocations.
- cogman10 6y agoCertainly. However, both of those things (from what I've seen) are fairly rare. The C++ copy constructor comes up fairly frequently.
- pjmlp 6y agoLike unsafe Rust code, there is the theory and then there are the code bases that one finds out in the wild on crates.io and in-house, not necessarily using best practices.
- dthul 6y agoRust does not have implicit type conversions.
- pjmlp 6y agoVia Deref.
- dthul 6y agoNot in practice. It's only used for reference coercions to existing objects. You would need to ignore the documentation and bend over backwards to use it for an actual type conversion, because you can only return references.
- pjmlp 6y agoBending backwards is a synonym to code quality delivered by consulting/offshoring projects across most big corporations.