看一下这段代码:
class Profiler{
const std::string id;
public:
Profiler(const std::string id);
Profiler(const Profiler &t);
//...
}
然后在代码的某处:
std::map<const std::string, Profiler> profilers;
以及其他地方我将容器填充为:
profilers.insert(std::pair<const std::string, Profiler>(id, Profiler(id)));
上述行总共调用了constructor
和copy constructor
3次。一个用于创建临时Profiler
,一个用于创建pair
,另一个用于创建insert
权限?
profilers[id] = Profiler(id);
也有相同数量的调用。
Profiler
并将其地址存储在堆中
map
? (Profiler
对象很小)感谢
答案 0 :(得分:0)
我的情况,就像我的其他情况一样,stack
更为可取。
为什么?
阅读比一个更好: