The C++ standard library comes with a few smart pointer types. The simplest one is unique_ptr
: This class babysits a raw pointer and remembers to delete it at destruction (in an appropriate manner). Dumping the contents of a unique_ptr
is just looking at the raw pointer inside.
Inside STL: Smart Pointers
By Raymond Chen
From the article:
The C++ standard library comes with a few smart pointer types.
The simplest one is
unique_ptr
: This class babysits a raw pointer and remembers to delete it at destruction (in an appropriate manner). Dumping the contents of aunique_ptr
is just looking at the raw pointer inside.The complication is that there is also a deleter object in the
unique_ptr
. This deleter object is usually an empty class, so it is stored as part of a compressed pair.The Visual Studio debugger has a visualizer that understands
unique_ptr
, but here’s what it looks like at a low level in the Microsoft implementation:0:000< ?? p class std::unique_ptr<S,std::default_delete<S> > +0x000 _Mypair : std::_Compressed_pair<std::default_delete<S>,S *,1> 0:000< ?? p._Mypair class std::_Compressed_pair<std::default_delete<S>,S *,1> +0x000 _Myval2 : 0x0000020a`11f08490 S 0:000< ?? p._Mypair._Myval2 struct S * 0x0000020a`11f08490 ← here is the unique object +0x000 a : 0n42
Add a Comment
Comments are closed.