std::pointer types — a tear down and discussion

<p>I was wanting to get a more complete understanding of exactly what code gets generated when we compile some typical smart pointer patterns in C++ so I created a sample app that did some of the things. I then looked at the disassembly and annotated it heavily. Now we should keep in mind that this is just one compiler, MSC, and it&#39;s on Windows, so the code would be different on Linux if only because the ABI is different and clang/gcc are likely to make some different choices overall. But I think it&#39;s still super interesting to dig into the output at this level.</p> <p>Below is the program I started with. Later I go into an &quot;overtime&quot; section where I added a few more small functions to look at some patterns. The source for those is included below but they are very small fragments so it isn&#39;t much anyway.</p> <p>Keep in mind that some of what is happening below is done just to ensure inlining doesn&#39;t make it all vanish, so there are some non-idiomatic patterns. I built with /O2 (prefer speed) which is likely to make different choices also. And I didn&#39;t enable any advanced security features or anything like that.</p> <p>So YMMV. But here it is.</p> <p><a href="https://ricomariani.medium.com/std-pointer-types-a-tear-down-and-discussion-76dc93d473dc">Visit Now</a></p>
Tags: pointer down