<div dir="ltr">Thanks for your answer, Even.<div><br></div><div>I would want that, yes, but I was prepared for the answer being no :(.</div><div><br></div><div>I also though computational complexity would be the problem, but I checked with VTune and it points the other way (malloc, free, realloc). Moreover, performance is worse each time I execute the same test in the same run, so I think that would match some memory fragmentation or something like that.</div><div><br></div><div>Thanks again,</div><div><br></div><div>Jesús Cano</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El jue., 30 abr. 2020 a las 11:24, Even Rouault (<<a href="mailto:even.rouault@spatialys.com">even.rouault@spatialys.com</a>>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div style="font-family:monospace;font-size:9pt;font-weight:400;font-style:normal">
<p style="margin:0px;text-indent:0px">Jesús,</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> I have been working with C/C++ and GDAL with GEOS for some time now and I</p>
<p style="margin:0px;text-indent:0px">> have a question about GDAL memory management.</p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> I wonder if there are any memory management options or tips to control</p>
<p style="margin:0px;text-indent:0px">> allocations and deallocations in the library since we are noticing</p>
<p style="margin:0px;text-indent:0px">> performance problems as our data increases in complexity, mainly OGR</p>
<p style="margin:0px;text-indent:0px">> operations (intersection, simplify).</p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> For example, I would expect something to do the same as:</p>
<p style="margin:0px;text-indent:0px">> - std::allocator: <a href="http://www.cplusplus.com/reference/memory/allocator/" target="_blank">http://www.cplusplus.com/reference/memory/allocator/</a></p>
<p style="margin:0px;text-indent:0px">> - CGAL allocator:</p>
<p style="margin:0px;text-indent:0px">> <a href="https://doc.cgal.org/latest/Manual/devman_memory_management.html" target="_blank">https://doc.cgal.org/latest/Manual/devman_memory_management.html</a></p>
<p style="margin:0px;text-indent:0px">> - SQLite memory allocation routines:</p>
<p style="margin:0px;text-indent:0px">> <a href="https://www.sqlite.org/c3ref/mem_methods.html" target="_blank">https://www.sqlite.org/c3ref/mem_methods.html</a></p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> I have been looking for it, but GDAL is so big that maybe I missed</p>
<p style="margin:0px;text-indent:0px">> something.</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">Interaction between GDAL and GEOS is in ogr/ogrgeometry.cpp and ogr/ogrgeometryfactory.cpp</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">Basically GDAL will export geometries to WKB and GEOS will instanciate its geometry object from it. The temporary WKB buffer created by GDAL is using CPLMalloc() that is just a wrapper over malloc().</p>
<p style="margin:0px;text-indent:0px">GEOS will likely use standard C++ memory operators (new, vector) etc.</p>
<p style="margin:0px;text-indent:0px">And ultimately GDAL will reconstruct a OGR Geometry from a GEOS WKB buffer, using a mix of C++ new and CPLMalloc</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">From the links you refering, it seems you'd want a way to use your own memory management routines. There's no such possibility in GDAL. CPLMalloc()/CPLRealloc()/CPLFree() could possibly be redirected to some callbacks.  On the C++ side, not sure what would be involved.</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">Are you really sure that the bottleneck you see are in memory allocations/deallocations themselves ? I'd expect more computational complexity to be the main limit.</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">Even</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">-- </p>
<p style="margin:0px;text-indent:0px">Spatialys - Geospatial professional services</p>
<p style="margin:0px;text-indent:0px"><a href="http://www.spatialys.com" target="_blank">http://www.spatialys.com</a></p></div></blockquote></div>