[gdal-dev] Starting a discussion on style and coding guidelines

Even Rouault even.rouault at spatialys.com
Thu May 5 07:31:05 PDT 2016

Le jeudi 05 mai 2016 16:14:34, David Strip a écrit :
> On 5/4/2016 4:30 PM, Kurt Schwehr wrote:
> <description of approach using std::vector>
> Drawbacks:
> It is possible to change the size of the vector later on in the code
> 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? Resizing the array could break anything that
> was using a C style array pointer to the vector’s data
>  Drawbacks one and three can be eliminated by deriving a class from vector
> that hides resize, so there really is only the single drawback of storage
> overhead and bookkeeping, which are often minor.

I'd not find it very attractive to create our own class just to prevent 
resizing for such a simple thing as an array of integers... "std::vector<int> 
oVals(256, 0)" is very readable. If it must not be resized for some reason, a 
comment should do.

One thing to keep in mind however is the potential impact of heap allocation 
in performance sensitive code paths.

Spatialys - Geospatial professional services

More information about the gdal-dev mailing list