4 ms·
> rather it relies on making new objects constantly, whereas with explicit functions, you can pass in an additional parameter that will take the result. We hav
by spacechild1 3y ago
> rather it relies on making new objects constantly, whereas with explicit functions, you can pass in an additional parameter that will take the result.
We have move semantics since C++11.
- gpderetta 3y agoAnd expression templates even before that.
- deleted 3y ago[deleted]
- dryanau 3y agoIt's not the same if you need to allocate memory for the result. If you could pass the result in by reference, then you could (re)use a buffer which has already been allocated. The difference is massive in things like matrix calculations or image processing where you have an inner loop or a real-time stream repeating similar calculations.
- bhouston 3y agoOr you are working with a language like JavaScript where math primitives are GC objects and thus quite costly. In those languages if you do not reduce object creation via reuse in this way, it can be very slow.