Highest Rated Comments


Crazy__Eddie6 karma

In Going Native, most of the panel seemed to agree that you should pass by value now rather than by const reference.

I did some ad-hoc measuring with the idea and found that when you pass temporaries it's indeed noticeably faster, if by a small margin. Of course, for cases like you talk about where there's a loop that can take advantage of repeated use of the same allocation space it's slower. That's a rather obvious case though.

I have some concerns with the pass by value policy even if it's faster. For functions that do not make copies of the parameter, but only refer to it as constant input, it's possible and probably likely, for client code to move from making a quick call with a temporary, to making a slow call with an lvalue. This is a silent switch from something generally faster, to something generally slower, that can easily be done during maintenance without warning or clue that's what happened.

I'm not sure you agreed with the recommended policy, it seemed maybe you did not, but my attempt to contact Abrahams (the author of the cited paper) to ask this question failed. I wonder if you might have input on this or perhaps ideas to alleviate my concern and make it a non-issue. Or reasons why it might be a cost worth paying of course.