{"id":6736,"date":"2023-11-29T16:39:49","date_gmt":"2023-11-29T22:39:49","guid":{"rendered":"https:\/\/www.logikalsolutions.com\/wordpress\/?p=6736"},"modified":"2023-11-29T16:39:51","modified_gmt":"2023-11-29T22:39:51","slug":"smart-pointers","status":"publish","type":"post","link":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/","title":{"rendered":"The Myth of Smart Pointers"},"content":{"rendered":"\n<p>On page 206 of <em><a href=\"https:\/\/www.oreilly.com\/library\/view\/beginning-c17-from\/9781484233665\/\">Beginning C++17<\/a><\/em> ISBN: 9781484233665 published in 2018 you will find the following about smart pointers. <\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Always use either the std::vector&lt;> container (to replace dynamic arrays) or a smart pointer (to dynamically allocate objects and manage their lifetimes). These high-level alternatives are much, much safer than the low-level memory management primitives and will help you tremendously . . .<\/p>\n<cite>Quote from the book<\/cite><\/blockquote>\n\n\n\n<p>While using std::vector&lt;> is usually good, the opinion expressed on smart pointers is just that, an opinion, and it is baseless. Repeating it is damning generations of C++ programmers to tracking down random crashes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">QML Programs Been Crashing From This for Years<\/h2>\n\n\n\n<p>You really should read <a href=\"https:\/\/www.logikalsolutions.com\/wordpress\/uncategorized\/so-you-cant-get-your-qt-models-to-work-with-qml\/\">this post<\/a> before continuing. In fact I&#8217;m going to include the drunk driving across all lanes image again here.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1004\" height=\"711\" src=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2021\/01\/qml-flow-2.png\" alt=\"drunk driving across all 3 lanes\" class=\"wp-image-4201\" srcset=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2021\/01\/qml-flow-2.png 1004w, https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2021\/01\/qml-flow-2-300x212.png 300w, https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2021\/01\/qml-flow-2-768x544.png 768w, https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2021\/01\/qml-flow-2-850x602.png 850w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/figure>\n\n\n\n<p>You create an object with unique_ptr&lt;T> in C++ and need to use it in some QML screen, say for a flickable list. QML, being one of the most incapable languages ever created can&#8217;t deal with it, so it has to hand it off to JavaScript. They don&#8217;t copy the object, they copy the address.<\/p>\n\n\n\n<p>The C++ lane has no idea the other lanes are still using the thing. It determines C++ no longer has any need for it and nukes it. No good way of predicting when this type of garbage collection will happen in your application. Later on QML decides it needs to refresh the display of that flickable list because some pixel might have changed. It asks JavaScript for the data to be re-rendered. Oops!<\/p>\n\n\n\n<p>Depending on your OS, that memory might still be owned by your process, so you get garbage instead of a crash. Normally the OS has claimed it and you get an access violation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Oh, I Just Won&#8217;t Use QML<\/h2>\n\n\n\n<p>While that is admirable, it doesn&#8217;t solve your problem. <\/p>\n\n\n\n<p>Do you know the programming language used to write every library you use in your program? Was it C? C doesn&#8217;t have unique_ptr&lt;> that&#8217;s a C++ thing. The Linux kernel and many of the libraries you link with are written in C.<\/p>\n\n\n\n<p>Most languages supported by one of the GNU compilers can generate libraries with functions using the C calling standard. On OpenVMS we had the DEC calling standard an all languages used it. We routinely had COBOL, BASIC, FORTRAN, and C modules working together in the same executable.  It does not matter if you call it an object in C++, to most other languages you are simply passing the address of a buffer. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">But You Can&#8217;t Copy a unique_ptr&lt;><\/h2>\n\n\n\n<p>That&#8217;s a steaming pile of excrement. <\/p>\n\n\n\n<p>The standard states you cannot make to unique_ptr&lt;> with the same pointer value within the same compilation unit. This also isn&#8217;t true. I&#8217;m on the latest version of LinuxMint with all updates applied.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#babed8;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:4;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#0F111A\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#include &lt;iostream&gt;\n#include &lt;iomanip&gt;\n#include &lt;cstdlib&gt;\n#include &lt;cstring&gt;\n#include &lt;string&gt;\n\n#include &quot;config.h&quot;\n\n\/\/*********\n\/\/\tYes you can copy a unique_ptr\n\/\/*********\n\n\/\/ make this global to simulate data held by something else\nchar *BUFFER_PTR {};\n\nvoid fun1( char *txt);\nvoid fun2();\n\nint main(int argc, char **argv) {\n\tstd::cout &lt;&lt; &quot;UniquePtr1&quot; &lt;&lt; std::endl;\n\tstd::cout &lt;&lt; &quot;Version &quot; &lt;&lt; UniquePtr1_VERSION_MAJOR &lt;&lt; &quot;.&quot; &lt;&lt; UniquePtr1_VERSION_MINOR &lt;&lt; std::endl;\n\n\t{\n\t\t\/\/ establish a buffer of nulls\n\t\tstd::unique_ptr&lt;char[]&gt; uptr {new char [2048]};\n\t\tfun1( uptr.get());\n\t\tstd::cout &lt;&lt; uptr.get() &lt;&lt; std::endl;\n\t}\n\tstd::cout &lt;&lt; &quot;out of scope now\\n&quot;;\n\n\tfun2();\n\tstd::cout &lt;&lt; BUFFER_PTR &lt;&lt; std::endl;\n\n\treturn (EXIT_SUCCESS);\n}\n\n\/\/ this simulates something a thread might do with a pointer.\n\/\/\nvoid fun1( char *txt)\n{\n\tBUFFER_PTR = txt;\n\tstrcpy( BUFFER_PTR, &quot;Mary had a little lamb&quot;);\n#if 0\n\tstd::unique_ptr&lt;char[]&gt; ghost(txt);\n\tstrcpy( ghost.get(), &quot;just some text&quot;);\n#endif\n}\n\n\/\/ depending on how fast garbage collection happens with unique_ptr\n\/\/ this should crash\n\/\/\nvoid fun2()\n{\n\tstrcpy( BUFFER_PTR, &quot;Rock-em Sock-em Robots&quot;);\n}\n\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-ocean\" style=\"background-color: #0F111A\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #89DDFF; font-style: italic\">#include<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">iostream<\/span><span style=\"color: #89DDFF\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF; font-style: italic\">#include<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">iomanip<\/span><span style=\"color: #89DDFF\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF; font-style: italic\">#include<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">cstdlib<\/span><span style=\"color: #89DDFF\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF; font-style: italic\">#include<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">cstring<\/span><span style=\"color: #89DDFF\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF; font-style: italic\">#include<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">string<\/span><span style=\"color: #89DDFF\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF; font-style: italic\">#include<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">config.h<\/span><span style=\"color: #89DDFF\">&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/*********<\/span><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/\tYes you can copy a unique_ptr<\/span><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/*********<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/ make this global to simulate data held by something else<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">char<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">*<\/span><span style=\"color: #BABED8\">BUFFER_PTR <\/span><span style=\"color: #89DDFF\">{};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">void<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #82AAFF\">fun1<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #C792EA\">char<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #C792EA\">*<\/span><span style=\"color: #BABED8; font-style: italic\">txt<\/span><span style=\"color: #89DDFF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">void<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #82AAFF\">fun2<\/span><span style=\"color: #89DDFF\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">int<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #82AAFF\">main<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #C792EA\">int<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #BABED8; font-style: italic\">argc<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #C792EA\">char<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #C792EA\">**<\/span><span style=\"color: #BABED8; font-style: italic\">argv<\/span><span style=\"color: #89DDFF\">)<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #FFCB6B\">std<\/span><span style=\"color: #89DDFF\">::<\/span><span style=\"color: #BABED8\">cout <\/span><span style=\"color: #89DDFF\">&lt;&lt;<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">UniquePtr1<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&lt;&lt;<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #FFCB6B\">std<\/span><span style=\"color: #89DDFF\">::<\/span><span style=\"color: #BABED8\">endl<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #FFCB6B\">std<\/span><span style=\"color: #89DDFF\">::<\/span><span style=\"color: #BABED8\">cout <\/span><span style=\"color: #89DDFF\">&lt;&lt;<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">Version <\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&lt;&lt;<\/span><span style=\"color: #BABED8\"> UniquePtr1_VERSION_MAJOR <\/span><span style=\"color: #89DDFF\">&lt;&lt;<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">.<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&lt;&lt;<\/span><span style=\"color: #BABED8\"> UniquePtr1_VERSION_MINOR <\/span><span style=\"color: #89DDFF\">&lt;&lt;<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #FFCB6B\">std<\/span><span style=\"color: #89DDFF\">::<\/span><span style=\"color: #BABED8\">endl<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #89DDFF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\t\t\/\/ establish a buffer of nulls<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F07178\">\t\t<\/span><span style=\"color: #FFCB6B\">std<\/span><span style=\"color: #89DDFF\">::<\/span><span style=\"color: #F07178\">unique_ptr<\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C792EA\">char<\/span><span style=\"color: #F07178\">[]<\/span><span style=\"color: #89DDFF\">&gt;<\/span><span style=\"color: #F07178\"> uptr <\/span><span style=\"color: #89DDFF\">{new<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #C792EA\">char<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #89DDFF\">[<\/span><span style=\"color: #F78C6C\">2048<\/span><span style=\"color: #89DDFF\">]};<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F07178\">\t\t<\/span><span style=\"color: #82AAFF\">fun1<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #BABED8\">uptr<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">get<\/span><span style=\"color: #89DDFF\">());<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F07178\">\t\t<\/span><span style=\"color: #FFCB6B\">std<\/span><span style=\"color: #89DDFF\">::<\/span><span style=\"color: #F07178\">cout <\/span><span style=\"color: #89DDFF\">&lt;&lt;<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #BABED8\">uptr<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">get<\/span><span style=\"color: #89DDFF\">()<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #89DDFF\">&lt;&lt;<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #FFCB6B\">std<\/span><span style=\"color: #89DDFF\">::<\/span><span style=\"color: #F07178\">endl<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F07178\">\t<\/span><span style=\"color: #89DDFF\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #FFCB6B\">std<\/span><span style=\"color: #89DDFF\">::<\/span><span style=\"color: #BABED8\">cout <\/span><span style=\"color: #89DDFF\">&lt;&lt;<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">out of scope now<\/span><span style=\"color: #BABED8\">\\n<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #82AAFF\">fun2<\/span><span style=\"color: #89DDFF\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #FFCB6B\">std<\/span><span style=\"color: #89DDFF\">::<\/span><span style=\"color: #BABED8\">cout <\/span><span style=\"color: #89DDFF\">&lt;&lt;<\/span><span style=\"color: #BABED8\"> BUFFER_PTR <\/span><span style=\"color: #89DDFF\">&lt;&lt;<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #FFCB6B\">std<\/span><span style=\"color: #89DDFF\">::<\/span><span style=\"color: #BABED8\">endl<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #89DDFF; font-style: italic\">return<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #BABED8\">EXIT_SUCCESS<\/span><span style=\"color: #89DDFF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/ this simulates something a thread might do with a pointer.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">void<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #82AAFF\">fun1<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #C792EA\">char<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #C792EA\">*<\/span><span style=\"color: #BABED8; font-style: italic\">txt<\/span><span style=\"color: #89DDFF\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\tBUFFER_PTR <\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\"> txt<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #82AAFF\">strcpy<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #BABED8\"> BUFFER_PTR<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">Mary had a little lamb<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #89DDFF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF; font-style: italic\">#if<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #F78C6C\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #FFCB6B\">std<\/span><span style=\"color: #89DDFF\">::<\/span><span style=\"color: #BABED8\">unique_ptr<\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C792EA\">char<\/span><span style=\"color: #BABED8\">[]<\/span><span style=\"color: #89DDFF\">&gt;<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #82AAFF\">ghost<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #BABED8\">txt<\/span><span style=\"color: #89DDFF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #82AAFF\">strcpy<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #BABED8\"> ghost<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">get<\/span><span style=\"color: #89DDFF\">(),<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">just some text<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #89DDFF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF; font-style: italic\">#endif<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/ depending on how fast garbage collection happens with unique_ptr<\/span><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/ this should crash<\/span><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">void<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #82AAFF\">fun2<\/span><span style=\"color: #89DDFF\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #82AAFF\">strcpy<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #BABED8\"> BUFFER_PTR<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">Rock-em Sock-em Robots<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #89DDFF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>I built this in Eclipse as one of their CMake projects which is why you see the config.h and initial std::cout lines. Run as-is and it &#8220;works.&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">UniquePtr1<br \/>Version 0.1<br \/>Mary had a little lamb<br \/>out of scope now<br \/>Rock-em Sock-em Robots<\/pre>\n\n\n\n<p>If garbage collection was immediate, this should have crashed. The memory pointed to by BUFFER_PTR should have been freed and we should get an access violation copying to memory we don&#8217;t own. Now, let&#8217;s change #if 0 to #if 1<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"768\" height=\"121\" src=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/11\/double-free.png\" alt=\"\" class=\"wp-image-6738\" srcset=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/11\/double-free.png 768w, https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/11\/double-free-300x47.png 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n\n\n\n<p>I kind of &#8220;not like&#8221; how Eclipse puts the exit\/error at the top of the output window. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Happened?<\/h2>\n\n\n\n<p>This is a case of garbage collection not being what you think. This is why every college worth even a fraction of its tuition makes you take an Assembly language class. They also make you take an operating systems class so you can understand different classes\/types of Heap.<\/p>\n\n\n\n<p>A cold allocation of RAM from the Far Heap, or Free Store, or System RAM, depending on what your OS calls it, is expensive. There are process level limits that have to be checked and other system level decisions before that chunk of RAM is assigned to your process. Every modern OS has a minimum allocation size, usually a memory Page.<\/p>\n\n\n\n<p>Once allocated, unless you make an OS specific call to force de-allocation, that unit of RAM remains with your process. (Some Operating Systems will request available RAM back from running processes when they get desperate, but let&#8217;s not have that discussion now.)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Near Heap<\/h2>\n\n\n\n<p>Long ago, during the horrible days of Segment::Offset addressing, near and far heap meant something different. It had to do with the Segment portion of the address. <\/p>\n\n\n\n<p>In the modern world this is the RAM already allocated to your process but unused. Some stack based programming languages put the stack out here so it can &#8220;grow.&#8221; Every compiler for every language I&#8217;ve ever worked with during modern times utilizes this and tends to refer to it as Near Heap. Far Heap (in today&#8217;s world) is memory you have to request from the operating system. That&#8217;s expensive per above, and it will add a minimum allocation unit of RAM to your process. The standard C\/C++ run-time basically does this for you behind the scenes.<\/p>\n\n\n\n<p>When you &#8220;free&#8221; RAM either via garbage collection or delete or free(), that gets added to your Near Heap. Your process still owns it. The next allocation may re-purpose it. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/chortle.ccsu.edu\/AssemblyTutorial\/Chapter-33\/fragmentation.gif\" alt=\"\"\/><\/figure>\n<\/div>\n\n\n<p>The point is, the Operating System gives you another allocation unit of RAM and the C\/C++ run-time can merrily bust it up any way it wants. As long as we play in that page or whatever it was, we don&#8217;t get access violations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Double Free<\/h2>\n\n\n\n<p>We got this error because the &#8220;compiler will only allow one unique_ptr per address&#8221; mantra is mostly kaka. Garbage collection is happening as soon as we go out of scope <em>but our RAM was not returned to the Operating System<\/em>. It was returned to the Near Heap. Memory our process has but isn&#8217;t using.<\/p>\n\n\n\n<p>When line 43 is #if 1, the memory we allocated for the first unique_ptr is garbage collected when we exit fun1. We can still write to it because it hasn&#8217;t left our process. (Note: single core processors with DOS-like simple operating systems will get different results. Bare metal can&#8217;t use this code because we are doing screen I\/O.)<\/p>\n\n\n\n<p>The return statement at line 34 is when the initial unique_ptr tries to give up the same RAM and the run-time realizes the RAM has already been freed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Is This Contrived?<\/h2>\n\n\n\n<p>No! I run into this exact problem in people&#8217;s code for medical devices. Someone thinks it is a good idea to use Smart Pointers then passes the value to library functions written in C and other languages. Usually these things are in their own threads. It can be <em>days<\/em> between the delete and the crash. What &#8220;causes&#8221; the crash per observational debugging won&#8217;t seem to have any obvious pattern.<\/p>\n\n\n\n<p>When trying to track down a ghost like crash, <em>nuke all of the Smart Pointers in the code<\/em>. Make them raw pointers and delete them when you know it is safe. Prior to the manual delete, put some unique values out there prior to the deletion and be certain to null out the pointer you just deleted. The unique values make it a lot easier to track down which pointer was actually the culprit.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>On page 206 of Beginning C++17 ISBN: 9781484233665 published in 2018 you will find the following about smart pointers. Always use either the std::vector&lt;> container (to replace dynamic arrays) or a smart pointer (to dynamically allocate objects and manage their lifetimes). These high-level alternatives are much, much safer than the low-level memory management primitives and will help you tremendously . . . Quote from the book While using std::vector&lt;> is usually good, the opinion expressed &hellip; <a title=\"The Myth of Smart Pointers\" class=\"bnm-read-more\" href=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/\"><span class=\"screen-reader-text\">The Myth of Smart Pointers<\/span>Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":6737,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1309,3],"tags":[1504,2177],"class_list":["post-6736","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-experience","category-information-technology","tag-c","tag-smart-pointers","bnm-entry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The Myth of Smart Pointers &#8211; Logikal Blog<\/title>\n<meta name=\"description\" content=\"On page 206 of Beginning C++17 ISBN: 9781484233665 published in 2018 you will find the following about smart pointers.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Myth of Smart Pointers &#8211; Logikal Blog\" \/>\n<meta property=\"og:description\" content=\"On page 206 of Beginning C++17 ISBN: 9781484233665 published in 2018 you will find the following about smart pointers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/\" \/>\n<meta property=\"og:site_name\" content=\"Logikal Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-29T22:39:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-29T22:39:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/11\/59.79_bw.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"976\" \/>\n\t<meta property=\"og:image:height\" content=\"1536\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"seasoned_geek\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"seasoned_geek\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/smart-pointers\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/smart-pointers\\\/\"},\"author\":{\"name\":\"seasoned_geek\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/c077f770ade13de7faaf616c3eac6842\"},\"headline\":\"The Myth of Smart Pointers\",\"datePublished\":\"2023-11-29T22:39:49+00:00\",\"dateModified\":\"2023-11-29T22:39:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/smart-pointers\\\/\"},\"wordCount\":1230,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/c077f770ade13de7faaf616c3eac6842\"},\"image\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/smart-pointers\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/59.79_bw.jpg\",\"keywords\":[\"C++\",\"smart pointers\"],\"articleSection\":[\"Experience\",\"Information Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/smart-pointers\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/smart-pointers\\\/\",\"url\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/smart-pointers\\\/\",\"name\":\"The Myth of Smart Pointers &#8211; Logikal Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/smart-pointers\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/smart-pointers\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/59.79_bw.jpg\",\"datePublished\":\"2023-11-29T22:39:49+00:00\",\"dateModified\":\"2023-11-29T22:39:51+00:00\",\"description\":\"On page 206 of Beginning C++17 ISBN: 9781484233665 published in 2018 you will find the following about smart pointers.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/smart-pointers\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/smart-pointers\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/smart-pointers\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/59.79_bw.jpg\",\"contentUrl\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/59.79_bw.jpg\",\"width\":976,\"height\":1536,\"caption\":\"Yad or Torah Pointer by Jewish is licensed under CC-BY 3.0\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/smart-pointers\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The Myth of Smart Pointers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#website\",\"url\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/\",\"name\":\"Logikal Blog\",\"description\":\"For people with attention spans longer than a Tweet\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/c077f770ade13de7faaf616c3eac6842\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/c077f770ade13de7faaf616c3eac6842\",\"name\":\"seasoned_geek\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r\",\"caption\":\"seasoned_geek\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r\"},\"description\":\"Roland Hughes started his IT career in the early 1980s. He quickly became a consultant and president of Logikal Solutions, a software consulting firm specializing in OpenVMS application and C++\\\/Qt touchscreen\\\/embedded Linux development. Early in his career he became involved in what is now called cross platform development. Given the dearth of useful books on the subject he ventured into the world of professional author in 1995 writing the first of the \\\"Zinc It!\\\" book series for John Gordon Burke Publisher, Inc. A decade later he released a massive (nearly 800 pages) tome \\\"The Minimum You Need to Know to Be an OpenVMS Application Developer\\\" which tried to encapsulate the essential skills gained over what was nearly a 20 year career at that point. From there \\\"The Minimum You Need to Know\\\" book series was born. Three years later he wrote his first novel \\\"Infinite Exposure\\\" which got much notice from people involved in the banking and financial security worlds. Some of the attacks predicted in that book have since come to pass. While it was not originally intended to be a trilogy, it became the first book of \\\"The Earth That Was\\\" trilogy: Infinite Exposure Lesedi - The Greatest Lie Ever Told John Smith - Last Known Survivor of the Microsoft Wars When he is not consulting Roland Hughes posts about technology and sometimes politics on his blog. He also has regularly scheduled Sunday posts appearing on the Interesting Authors blog.\",\"sameAs\":[\"https:\\\/\\\/theminimumyouneedtoknow.com\"],\"url\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/author\\\/seasoned_geek\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The Myth of Smart Pointers &#8211; Logikal Blog","description":"On page 206 of Beginning C++17 ISBN: 9781484233665 published in 2018 you will find the following about smart pointers.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/","og_locale":"en_US","og_type":"article","og_title":"The Myth of Smart Pointers &#8211; Logikal Blog","og_description":"On page 206 of Beginning C++17 ISBN: 9781484233665 published in 2018 you will find the following about smart pointers.","og_url":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/","og_site_name":"Logikal Blog","article_published_time":"2023-11-29T22:39:49+00:00","article_modified_time":"2023-11-29T22:39:51+00:00","og_image":[{"width":976,"height":1536,"url":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/11\/59.79_bw.jpg","type":"image\/jpeg"}],"author":"seasoned_geek","twitter_card":"summary_large_image","twitter_misc":{"Written by":"seasoned_geek","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/#article","isPartOf":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/"},"author":{"name":"seasoned_geek","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#\/schema\/person\/c077f770ade13de7faaf616c3eac6842"},"headline":"The Myth of Smart Pointers","datePublished":"2023-11-29T22:39:49+00:00","dateModified":"2023-11-29T22:39:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/"},"wordCount":1230,"commentCount":2,"publisher":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#\/schema\/person\/c077f770ade13de7faaf616c3eac6842"},"image":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/#primaryimage"},"thumbnailUrl":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/11\/59.79_bw.jpg","keywords":["C++","smart pointers"],"articleSection":["Experience","Information Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/","url":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/","name":"The Myth of Smart Pointers &#8211; Logikal Blog","isPartOf":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/#primaryimage"},"image":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/#primaryimage"},"thumbnailUrl":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/11\/59.79_bw.jpg","datePublished":"2023-11-29T22:39:49+00:00","dateModified":"2023-11-29T22:39:51+00:00","description":"On page 206 of Beginning C++17 ISBN: 9781484233665 published in 2018 you will find the following about smart pointers.","breadcrumb":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/#primaryimage","url":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/11\/59.79_bw.jpg","contentUrl":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/11\/59.79_bw.jpg","width":976,"height":1536,"caption":"Yad or Torah Pointer by Jewish is licensed under CC-BY 3.0"},{"@type":"BreadcrumbList","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.logikalsolutions.com\/wordpress\/"},{"@type":"ListItem","position":2,"name":"The Myth of Smart Pointers"}]},{"@type":"WebSite","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#website","url":"https:\/\/www.logikalsolutions.com\/wordpress\/","name":"Logikal Blog","description":"For people with attention spans longer than a Tweet","publisher":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#\/schema\/person\/c077f770ade13de7faaf616c3eac6842"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.logikalsolutions.com\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#\/schema\/person\/c077f770ade13de7faaf616c3eac6842","name":"seasoned_geek","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r","url":"https:\/\/secure.gravatar.com\/avatar\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r","caption":"seasoned_geek"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r"},"description":"Roland Hughes started his IT career in the early 1980s. He quickly became a consultant and president of Logikal Solutions, a software consulting firm specializing in OpenVMS application and C++\/Qt touchscreen\/embedded Linux development. Early in his career he became involved in what is now called cross platform development. Given the dearth of useful books on the subject he ventured into the world of professional author in 1995 writing the first of the \"Zinc It!\" book series for John Gordon Burke Publisher, Inc. A decade later he released a massive (nearly 800 pages) tome \"The Minimum You Need to Know to Be an OpenVMS Application Developer\" which tried to encapsulate the essential skills gained over what was nearly a 20 year career at that point. From there \"The Minimum You Need to Know\" book series was born. Three years later he wrote his first novel \"Infinite Exposure\" which got much notice from people involved in the banking and financial security worlds. Some of the attacks predicted in that book have since come to pass. While it was not originally intended to be a trilogy, it became the first book of \"The Earth That Was\" trilogy: Infinite Exposure Lesedi - The Greatest Lie Ever Told John Smith - Last Known Survivor of the Microsoft Wars When he is not consulting Roland Hughes posts about technology and sometimes politics on his blog. He also has regularly scheduled Sunday posts appearing on the Interesting Authors blog.","sameAs":["https:\/\/theminimumyouneedtoknow.com"],"url":"https:\/\/www.logikalsolutions.com\/wordpress\/author\/seasoned_geek\/"}]}},"_links":{"self":[{"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/posts\/6736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/comments?post=6736"}],"version-history":[{"count":0,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/posts\/6736\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/media\/6737"}],"wp:attachment":[{"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/media?parent=6736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/categories?post=6736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/tags?post=6736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}