Coding guideline : When dealing with large data in the output of a function should it be return value or argument with reference? #3209
Replies: 4 comments 2 replies
-
@yukkysaito Thank you for creating this discussion thread! First, there are several cases that
However, even if Also, the performance of FYI, with Clang, even Based on these results, I recommend using Please let me know if there are any mistakes in my investigation methods or results. |
Beta Was this translation helpful? Give feedback.
-
Regarding this part, I think it's not fair to only reference the projects mainly written before C++11. They may have guidelines that differ from modern standards. |
Beta Was this translation helpful? Give feedback.
-
I have doubts about the potential drawbacks of using return-value. No negative behavior was found in either the report from @kenji-miyake or my investigation. (It is known the NRVO is not guaranteed, but the compiler will optimize it anyway, and maybe it calls Additionally, there are some popular guidelines suggesting the use of return-value. Unless evidence of a significant problem arises, there seems to be no benefit in deviating from these guidelines and using a different approach. Note: of cause, there are cases where using reference value is preferred, for example, modifying a few fields in a large object. However, it can not be a reason to prohibit using return-value in all situations. It totally depends on each implementation. |
Beta Was this translation helpful? Give feedback.
-
In conclusion, even if the data is large, I would go in the direction of using return values. |
Beta Was this translation helpful? Give feedback.
-
Background : autowarefoundation/autoware.universe#1947 (comment)
I would like to discuss the coding policy when outputting large data in a function.
In the current code, the following two types of functions are employed.
For readability, the return value is better. But, the reason for not using the return value is that memory copying may occur.
Memory copying affects execution time and squeezes memory bandwidth. In TIER IV, in-vehicle computers could not process due to insufficient memory bandwidth.
Each of these has its own good and bad points.
Argument with reference
Return value
If the data size is small, readability should be a priority, but if the data size is large, we need opinions on what should be prioritized.
We need opinions not only from algorithm engineers, but also from embedded computing engineers and others.
Beta Was this translation helpful? Give feedback.
All reactions