Quick Q: How can unique_ptr have no overhead if it needs to store the deleter?

Quick A: The default deleter does not store anything.

Recently on SO:

How can unique_ptr have no overhead if it needs to store the deleter?

std::unique_ptr<T> is quite likely to be zero-overhead (with any sane standard-library implementation). std::unique_ptr<T, D>, for an arbitrary D, is not in general zero-overhead.

The reason is simple: Empty-Base Optimisation can be used to eliminate storage of the deleter in case it's an empty (and thus stateless) type (such as std::default_delete instantiations).

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.