If I return a big vector like std::vector<int>
which contains like 10,000 members, will there be massive data copy? Or is there some smart mechanism like using a pointer automatically?
Asked
Active
Viewed 29 times
0

Remy Lebeau
- 555,201
- 31
- 458
- 770

Chan Kim
- 5,177
- 12
- 57
- 112
-
2If you return it by value, there will be copy. If you return using move, or your compiler intelligently applies RVO, not so much. Your debugger and profiler are the best tools for answering this question. – 3Dave Nov 29 '19 at 02:52
-
1This depends on your specific compiler and the language version you are using. If your compiler supports copy elision/return value optimization, or you are using a version of C++ that requires copy elision/return value optimization in specific situations that apply to your code, no copy will take place. The linked question provides a canonical answer. For your specific compiler, consult its documentation. – Sam Varshavchik Nov 29 '19 at 02:57