Moa*_*sry 7 c++ performance stl c++11
让我说我有功能
std::Vector<Point> calculate() {
std::Vector<Point> points; //do stuff with points
return points;
}
Run Code Online (Sandbox Code Playgroud)
和
void calculate(std::Vector<Point>& points) {
//do stuff with points
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是特定于在堆栈上初始化的对象,并且是stl对象.性能有什么不同,这种流行的方法是什么
问候
Nic*_*las 11
将值作为参考参数具有以下属性:
返回值具有以下属性:
由于复制省略,性能很可能是相同的.
这两种方法表达的是不同的
std::vector<Point> calculate()
Run Code Online (Sandbox Code Playgroud)
返回一个向量(可能基于一些参数).
void calculate(std::vector<Point>& points)
Run Code Online (Sandbox Code Playgroud)
修改现有向量(同样,可能基于参数).