3 ms·
Transparently copyable heap-allocated object would are a recipe for introducing invisible performance issues, especially in generic code. Rust requires types t
by codewiz 3y ago
Transparently copyable heap-allocated object would are a recipe for introducing invisible performance issues, especially in generic code.
Rust requires types to explicitly opt-in to being implicitly copied, while C++ requires you to opt-out by deleting the copy-constructor.
Accidentally copying small structs on the stack is a minor performance problem. Copying an std::box<int> in a hot loop could cause heap fragmentation, lock contention and huge amounts of wasted memory due to heap alignment requirements (32 bytes on 64-bit arches).
- mike_hock 3y agoYou mean, as opposed to the other transparently copyable heap-allocated objects such as ... std::vector, std::list, std::unordered_map, std::string, ... basically most of the standard library other than the smart pointers? The problem is already there, Box wouldn't change anything.