FAQ - Miscellaneous
- Is the GDAL library thread-safe?
- Does GDAL work in different international numeric locales?
- How do I debug GDAL?
- How should I deallocate resources acquainted from GDAL on Windows?
- C API vs C++ API
- How do I suppress warning encountered in Python API?
- What are configuration options, and what ones exist?
Is the GDAL library thread-safe?
No. GDAL is not completely thread safe.
However for GDAL 1.3.0 much work has been done on making some common scenarios thread safe. In particular for the situation where many threads are reading from GDAL datasets at once should work as long as no two threads access the same GDALDataset object at the same time. However, in this scenario, no threads can be writing to GDAL while others are reading or chaos may ensue.
Also, while the GDAL core infrastructure is now thread-safe for this specific case, only a few drivers have been vetted to be thread safe.
It is intended that work will continue on improving GDAL's thread safety in future versions.
Does GDAL work in different international numeric locales?
No. GDAL makes extensive use of sprintf() and atof() internally to translate numeric values. If a locale is in effect that modifies formatting of numbers, altering the role of commas and periods in numbers, then PROJ.4 will not work. This problem is common in some European locales.
On Unix-like platforms, this problem can be avoided by forcing the use of the default numeric locale by setting the LC_NUMERIC environment variable to C, e.g.
$ export LC_NUMERIC=C $ gdalinfo abc.tif
How do I debug GDAL?
Various helpful debugging information will be produced by GDAL and OGR if the CPL_DEBUG environment variable is set to the value ON. Review the documentation for the CPLDebug() function for more information on built-in debugging messages.
For versions prior to GDAL 1.5, on Unix operating systems GDAL can be built with the CFG environment variable set to debug to enable debugger support with the -g compiler switch. For GDAL versions 1.5+, you can enable debugging symbols with the --enable-debug configure switch.
On Windows edit the nmake.opt and ensure /Zi appears in the OPTFLAGS variable.
How should I deallocate resources acquainted from GDAL on Windows?
The safest way to release resources allocated and returned (with ownership transfered to caller) from GDAL library is to use dedicated deallocator function. Deallocators promise to release resources on the right module side, without crossing modules boundaries what usually causes memory access violation errors.
- Example of correct resource deallocation:
OGRDataSource* poDS = NULL; // OGRDataSource aquisition made on side of the GDAL module poDS = OGRSFDriverRegistrar::Open( "point.shp", FALSE ); // ... // Properly resource release using deallocator function OGRDataSource::DestroyDataSource( poDS );
* Example of incorrect resource deallocation:
OGRDataSource* poDS = NULL; // OGRDataSource aquisition made on side of the GDAL module poDS = OGRSFDriverRegistrar::Open( "point.shp", FALSE ); // ... // Deallocation across modules boundaries. // Here, the deallocation crosses GDAL DLL library and client's module (ie. executable module) delete poDS;
More detailed explanation of the problem can be found in following articles:
- 1st possible cause of segmentation fault in a dll
- Allocating and freeing memory across module boundaries
C API vs C++ API
If you intend writing code using GDAL/OGR that will not require recompilation when run against different GDAL/OGR versions, you should try to stick to the C API when possible. Although the changes in the C++ API are generally made in a upward compatible way, the C++ ABI might change from a minor release to another one (for example from GDAL 1.5.0 to GDAL 1.6.0) due to additions of new virtual methods, new member variables to core classes, etc.
How do I suppress warning encountered in Python API?
Set error handler to quite one:
What are configuration options, and what ones exist?
Configuration options are values the user or application developer can set at runtime to affect the behavior of the library. Details and a partial listing of options are available in the ConfigOptions page.