An Exploration of the Deleter on the Memory Footprint of std::unique_ptr

The devil is in the details.

(…or “How I Learned to Love the Tuple.”)

Although the C++ standard does not explicitly spell it out, one may hope for a sophisticated implementation of the std::unique_ptr that consumes exactly as much memory as the pointer it tracks when it is configured to use a empty-class deleter (such as the default deleter type). The unique_ptr indeed allows the consumer to supply a custom deleter, which one intuitively expects to consume memory — if you store two pieces of data, you will consume two spots in memory somehow, right? Not quite. I will explore how this is done (specifically in GCC).

Continue reading “An Exploration of the Deleter on the Memory Footprint of std::unique_ptr