How much is the overhead of smart pointers compared to normal pointers in C++11? In other words, is my code going to be slower if I use smart pointers, and if so, how much slower?
Specifically, I'm asking about the C++11 std::shared_ptr
and std::unique_ptr
.
Obviously, the stuff pushed down the stack is going to be larger (at least I think so), because a smart pointer also needs to store its internal state (reference count, etc), the question really is, how much is this going to affect my performance, if at all?
For example, I return a smart pointer from a function instead of a normal pointer:
std::shared_ptr<const Value> getValue();
// versus
const Value *getValue();
Or, for example, when one of my functions accept a smart pointer as parameter instead of a normal pointer:
void setValue(std::shared_ptr<const Value> val);
// versus
void setValue(const Value *val);
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…