<div dir="ltr">Hi all,<div><br></div><div>If you've been watching the timeline on trac, you have probably seen a large number of cleanup CLs from me.  It's definitely past time to get some discussion going on these changes.  If the community likes these, we can add them to <a href="https://trac.osgeo.org/gdal/wiki/rfc8_devguide">rfc8_devguide</a>.  We also need to consider tools that help committers push code towards what we want and keep it there once it conforms to those guides (e.g. clang-format with a custom GDAL specification)  If you haven't see one of the changes I've committed yet, here is an example to check out... this change to geotiff.cpp is likely the biggest I will ever do.</div><div><br></div><div><a href="https://trac.osgeo.org/gdal/changeset/34130/">https://trac.osgeo.org/gdal/changeset/34130/</a><br></div><div><br></div><div>I personally think the goals of style / coding guidelines are:</div><div><br></div><div>0. Ensure that GDAL is around for a long time to come</div><div>1. Make the code easier to read (which particular patterns to use and consistent formatting)</div><div>2. When the code has trouble or data is bad, fail with error messages rather than crash</div><div>3. Make it easier for debuggers to present sensible state</div><div>4. Help static (clang static analyzer, Coverity, etc. ) and dynamic (e.g. fuzzers) analyzers perform better</div><div>5. Make it easier for authors to contribute code that plays well with the rest of system with the least possible effort</div><div><br></div><div>To start off the conversation, I wrote up a doc on changing large C arrays on the stack to std::vectors to get this data off of the stack and to simplify initialization.  I've attached the doc inline, but it is also available here:</div><div><br></div><div><a href="http://goo.gl/vuA3D6">goo.gl/vuA3D6</a><br></div><div><br></div><div>The full url is: <a href="https://docs.google.com/document/d/1Y9flzxj3Uz1vTEPCBmlswgi470m8i-oepGutVkbowfc/pub">https://docs.google.com/document/d/1Y9flzxj3Uz1vTEPCBmlswgi470m8i-oepGutVkbowfc/pub</a></div><div><br></div><div>It would be great to get people to have at commenting on this proposal.  If you all like this kind of thing, we can more of them and work them into a form that extends RFC 8.  Please don't be shy in commenting any way you feel is constructive on this doc.  We can discuss on this list or if people really want, I can give individuals comment access to the Google doc.</div><div><br></div><div>cheers,</div><div>-kurt</div><div><br></div><div><br></div><div><span id="docs-internal-guid-0b509e3e-7dde-87d0-f7e4-b6ef1bd7d820"><h2 dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:16px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Use </span><span style="font-size:16px;font-family:"Courier New";color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">vector<T>(length, initial_value)</span><span style="font-size:16px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> for local blocks of storage.</span></h2><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Author: Kurt Schwehr </span><a href="mailto:schwehr@google.com" style="text-decoration:none"><span style="font-size:14.6667px;font-family:Arial;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">schwehr@google.com</span></a><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> / </span><a href="mailto:schwehr@gmail.com" style="text-decoration:none"><span style="font-size:14.6667px;font-family:Arial;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">schwehr@gmail.com</span></a><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> (goatbar)</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Date: 2016-May-04</span></p><br><h3 dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Consider:</span></h3><br><div dir="ltr" style="margin-left:0pt"><table style="border:none;border-collapse:collapse;width:624px"><colgroup><col width="*"></colgroup><tbody><tr style="height:0px"><td style="border:0px solid rgb(0,0,0);vertical-align:top;padding:7px;background-color:rgb(244,204,204)"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:"Courier New";color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">   int anVals[256];</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:"Courier New";color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">   memset(anVals, 0, 256*sizeof(int));</span></p></td></tr></tbody></table></div><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">This is less than optimal because:</span></p><br><ul style="margin-top:0pt;margin-bottom:0pt"><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">It puts 1K or 2K on the stack, some of us (who can have huge numbers of threads) try to keep stack usage to 16K per thread</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">You have two places that need to know the size</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">The variable exists uninitialized between the definition and initialization</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">memset is a C API, which is able to do fewer sanity checks</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">No bounds checking</span></p></li></ul><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">In GDAL, there are >700 stack allocations of more than 100 items and > 150 of 1000 or more items.  There are 877 calls to memset in the C++ code.</span></p><br><h3 dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Proposed solution:</span></h3><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">  </span><a href="https://trac.osgeo.org/gdal/changeset/34177" style="text-decoration:none"><span style="font-size:14.6667px;font-family:Arial;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">https://trac.osgeo.org/gdal/changeset/34177</span></a><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> </span></p><br><div dir="ltr" style="margin-left:0pt"><table style="border:none;border-collapse:collapse;width:624px"><colgroup><col width="*"></colgroup><tbody><tr style="height:0px"><td style="border:0px solid rgb(0,0,0);vertical-align:top;padding:7px;background-color:rgb(217,234,211)"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:"Courier New";color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">  std::vector<int> oVals(256, 0);</span></p></td></tr></tbody></table></div><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Benefits:</span></p><br><ul style="margin-top:0pt;margin-bottom:0pt"><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">It can pretty much be used like a C array,  e.g., </span><span style="font-size:14.6667px;font-family:"Courier New";vertical-align:baseline;white-space:pre-wrap;background-color:transparent">++anVals[index];</span><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> works</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Using vector gets most of the memory off of the stack and into the heap helping threaded programs</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">The values are all initialized when anVals is created</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">If functions need to get a pointer to a C style array, you can call Foo(&anVals[0])</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Compilers can optimize the standard containers.</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Bounds checking is possible without having to resort to ASAN (which not all compilers have) or Valgrind</span></p></li></ul><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Drawbacks:</span></p><br><ul style="margin-top:0pt;margin-bottom:0pt"><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">It is possible to change the size of the vector later on in the code</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Vector has some storage overhead and bookkeeping that has to be done (but often the compiler can probably optimize away most of that). TODO: References that explain this?</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Resizing the array could break anything that was using a C style array pointer to the vector’s data</span></p></li></ul><br><h3 dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Alternatives </span></h3><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Might be better or worse in different ways:</span></p><br><ul style="margin-top:0pt;margin-bottom:0pt"><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Use std::fill instead of memset</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Declare and pass around the array size as a constant, e.g., const int knValsSize = 256.</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">CPL_ARRAY_SIZE to only have one 256 around</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Use CPLCalloc to put it on the heap and initialize</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Use new[] to put it on the heap</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Use </span><a href="http://www.cplusplus.com/reference/array/" style="text-decoration:none"><span style="font-size:14.6667px;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">std::array</span></a><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">.  Introduced in C++ 11, so currently disallowed.  Still puts the payload on the stack.</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Use </span><a href="http://en.cppreference.com/w/cpp/memory/unique_ptr" style="text-decoration:none"><span style="font-size:14.6667px;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">std::unique_ptr</span></a><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> to put it on the heap. Introduced in C++ 11, so currently disallowed</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Add autoptr to GDAL to put it on the heap.  autoptr is very similar to unique_ptr, but works with C++03</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Use some other library like boost.  That would require a major change to GDALs build requirements.</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">int anVals[256] = { 0 };  Only initializes the first element or you must specify all 256 elements. </span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Make our own simple class that handles allocation on the heap and cleans up in the destructor and provides operator[]</span></p></li></ul><br><h3 dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Key GDAL facts to keep in mind:</span></h3><br><ul style="margin-top:0pt;margin-bottom:0pt"><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Only C++03 is currently allowed</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Want to focus on maintainability and readability of code</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">A very diverse set of people work on the GDAL code base</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Currently support a wide range of compilers / platforms:</span></p></li><ul style="margin-top:0pt;margin-bottom:0pt"><li dir="ltr" style="list-style-type:circle;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">32 and 64 bit</span></p></li><li dir="ltr" style="list-style-type:circle;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Linux, Android, MacOSX, Windows >= Win7, Cigwin</span></p></li><li dir="ltr" style="list-style-type:circle;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Big and little endian</span></p></li><li dir="ltr" style="list-style-type:circle;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">GCC 4.8, GCC 5.2, MingW, VC9, VC12, VC13</span></p></li><li dir="ltr" style="list-style-type:circle;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Build with C++03, C++11, C++14</span></p></li><li dir="ltr" style="list-style-type:circle;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Build with C89, C99, C11</span></p></li><li dir="ltr" style="list-style-type:circle;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Python 2.7 and >= 3.5  (we might actually support 2.6 and 3.4, Idonno) </span></p></li><li dir="ltr" style="list-style-type:circle;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href="https://travis-ci.org/rouault/gdal_coverage/builds/" style="text-decoration:none"><span style="font-size:14.6667px;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">https://travis-ci.org/rouault/gdal_coverage/builds/</span></a><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> </span></p></li><li dir="ltr" style="list-style-type:circle;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href="https://ci.appveyor.com/project/rouault/gdal-coverage/history" style="text-decoration:none"><span style="font-size:14.6667px;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">https://ci.appveyor.com/project/rouault/gdal-coverage/history</span></a><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> </span></p></li></ul><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Want to help Coverity, Address Sanitizer, AFL, Clang Static Analyzer</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">GDAL uses a form of </span></p></li></ul><br><h3 dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">What if ...:</span></h3><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">GDAL goes with C++11 or 14?  It would probably be best to stick with the vector solution as it is simpler than unqiue_ptr and std::array still puts a large amount of data off the stack.   vector is still the simplest with initialization.</span></p><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">GDAL does not care about stack size and C++14?  You could do a unqiue_ptr with a CPLCalloc and a deleter of CPLFree.</span></p><br><ul style="margin-top:0pt;margin-bottom:0pt"><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">std::unique_ptr<std::array<int, 256>> Vals(new std::array<int, 256>());</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">std::unique_ptr<int *, std::function<void(char *)>> Vals(CPLCalloc(256, 0), CPLFree);</span></p></li><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">std::unique_ptr<int *, CplFreeDeleter> Vals( CPLCalloc(256, 0), CPLFree);</span></p></li><ul style="margin-top:0pt;margin-bottom:0pt"><li dir="ltr" style="list-style-type:circle;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.32955;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;color:rgb(136,0,0);vertical-align:baseline;white-space:pre-wrap">// Function object that calls GDAL's CPLFree on its parameter.</span><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap"><br class=""></span><span style="font-size:14.6667px;color:rgb(0,0,136);vertical-align:baseline;white-space:pre-wrap">struct</span><a href="https://cs.corp.google.com/piper///depot/google3/third_party/gdal/autotest2/cpp/util/cpl_memory.h?l=10&gs=cpp%253Aautotest2%253A%253Aclass-CplFreeDeleter%2540google3%252Fthird_party%252Fgdal%252Fautotest2%252Fcpp%252Futil%252Fcpl_memory.h%257Cdef&gsn=CplFreeDeleter&ct=xref_usages" style="text-decoration:none"><span style="font-size:14.6667px;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"> </span><span style="font-size:14.6667px;color:rgb(85,26,139);vertical-align:baseline;white-space:pre-wrap">CplFreeDeleter</span></a><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap"> {</span><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap"><br class=""></span><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap">  </span><span style="font-size:14.6667px;color:rgb(0,0,136);vertical-align:baseline;white-space:pre-wrap">void</span><a href="https://cs.corp.google.com/piper///depot/google3/third_party/gdal/autotest2/cpp/util/cpl_memory.h?l=11&gs=cpp%253Aautotest2%253A%253Aclass-CplFreeDeleter%253A%253Aoperator()(void%2B*)%2540google3%252Fthird_party%252Fgdal%252Fautotest2%252Fcpp%252Futil%252Fcpl_memory.h%257Cdef&gsn=operator()&ct=xref_usages" style="text-decoration:none"><span style="font-size:14.6667px;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"> </span><span style="font-size:14.6667px;color:rgb(0,0,136);vertical-align:baseline;white-space:pre-wrap">operator</span><span style="font-size:14.6667px;color:rgb(85,26,139);vertical-align:baseline;white-space:pre-wrap">()</span></a><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap">(</span><span style="font-size:14.6667px;color:rgb(0,0,136);vertical-align:baseline;white-space:pre-wrap">void</span><a href="https://cs.corp.google.com/piper///depot/google3/GENERATED/figments/cpp/PointerTo/void.cc?l=3&ct=xref_jump_to_def&cl=GROK&gsn=*" style="text-decoration:none"><span style="font-size:14.6667px;color:rgb(85,26,139);vertical-align:baseline;white-space:pre-wrap">*</span></a><a href="https://cs.corp.google.com/piper///depot/google3/third_party/gdal/autotest2/cpp/util/cpl_memory.h?l=11&gs=cpp%253Aautotest2%253A%253Aclass-CplFreeDeleter%253A%253Aoperator()(void%2B*)%253A%253Aparam-ptr%2540google3%252Fthird_party%252Fgdal%252Fautotest2%252Fcpp%252Futil%252Fcpl_memory.h%257Cdef&gsn=ptr&ct=xref_usages" style="text-decoration:none"><span style="font-size:14.6667px;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"> </span><span style="font-size:14.6667px;color:rgb(85,26,139);vertical-align:baseline;white-space:pre-wrap">ptr</span></a><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap">) {</span><a href="https://cs.corp.google.com/piper///depot/google3/blaze-out/gcc-4.X.Y-crosstool-v18-hybrid-grtev4-k8-fastbuild/include/third_party/gdal/_/gdal/third_party/gdal/port/cpl_conv.h?l=72&ct=xref_jump_to_def&cl=GROK&gsn=CPLFree" style="text-decoration:none"><span style="font-size:14.6667px;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"> </span><span style="font-size:14.6667px;color:rgb(85,26,139);vertical-align:baseline;white-space:pre-wrap">CPLFree</span></a><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap">(</span><a href="https://cs.corp.google.com/piper///depot/google3/third_party/gdal/autotest2/cpp/util/cpl_memory.h?l=11&ct=xref_jump_to_def&cl=GROK&gsn=ptr" style="text-decoration:none"><span style="font-size:14.6667px;color:rgb(85,26,139);vertical-align:baseline;white-space:pre-wrap">ptr</span></a><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap">); }</span><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap"><br class=""></span><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap">};</span></p></li></ul><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">std::unique_ptr<int[]> Vals(new int[256]);</span></p></li></ul><br><h3 dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Open questions:</span></h3><br><ul style="margin-top:0pt;margin-bottom:0pt"><li dir="ltr" style="list-style-type:disc;font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;background-color:transparent"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">At what size do we want to make as the initial threshold to recommend heap verses stack?  32 bytes seems like no big deal on the stack and 512 bytes seems like it really needs to be on the heap without a specific reason.</span></p></li></ul><br><h3 dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">See also:</span></h3><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href="https://trac.osgeo.org/gdal/ticket/5748" style="text-decoration:none"><span style="font-size:14.6667px;font-family:Arial;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">https://trac.osgeo.org/gdal/ticket/5748</span></a><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> Reduce GDAL stack usage</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href="https://google.github.io/styleguide/cppguide.html#Local_Variables" style="text-decoration:none"><span style="font-size:14.6667px;font-family:Arial;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">https://google.github.io/styleguide/cppguide.html#Local_Variables</span></a><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> </span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href="http://stackoverflow.com/questions/22571052/replace-fixed-size-arrays-with-stdarray" style="text-decoration:none"><span style="font-size:14.6667px;font-family:Arial;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">http://stackoverflow.com/questions/22571052/replace-fixed-size-arrays-with-stdarray</span></a><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> </span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href="http://stackoverflow.com/questions/15294129/overhead-to-using-stdvector" style="text-decoration:none"><span style="font-size:14.6667px;font-family:Arial;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">http://stackoverflow.com/questions/15294129/overhead-to-using-stdvector</span></a><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> </span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href="about:blank" style="text-decoration:none"><span style="font-size:14.6667px;font-family:Arial;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">http://www.cplusplus.com/reference/memory/unique_ptr/operator[]/</span></a></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href="http://stackoverflow.com/questions/16711697/is-there-any-use-for-unique-ptr-with-array" style="text-decoration:none"><span style="font-size:14.6667px;font-family:Arial;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">http://stackoverflow.com/questions/16711697/is-there-any-use-for-unique-ptr-with-array</span></a><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> </span></p><br><h3 dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Acknowledgements:</span></h3><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Several Google engineers commented on an initial draft of this doc.</span></p><br><br></span></div><div><br></div></div>