[Gdal-dev] locale handling in GDAL
warmerdam at pobox.com
Mon Mar 6 13:56:46 EST 2006
Kirk McKelvey wrote:
> This has not been our preferred solution since this policy would have
> had to be integrated into our coding practices if future wkt-parsing
> problems were to be avoided. So that is one vote in favor of GDAL
> setting the locale internally.
> On the other hand, we have gotten bitten with similar workarounds in the
> past. When using setlocale() in tight loops performance would go
> through the floor; apparently it is not a cheap operation. So if GDAL
> sets locale internally then I have no way to mitigate the performance
> issues that will come up from calling GDAL functions in tight loops. So
> that is one vote against GDAL setting the locale internally.
Right. While I hadn't done any tests, I was also concerned that performance
would be substantially affected. Your indication that setlocale() is
a fairly expensive operations is very useful to know.
I did a quick test on Linux and a program that calls setlocale() with
a value that doesn't result in a change 1000000 times takes roughly
1/20th of a second. Doing the same in a way that results in a change
takes most of a second. So changing locale is far from free, though
in the common case that things are already in the C locale it would
apparently not take very long.
I can't test on windows just now as my daughter is watching movies. :-)
> Ideally GDAL would *not* fiddle with the locale. Instead it would only
> use locale-sensitive functions when dealing with strings that are in the
> locale (mainly user input and output), and "something else" when dealing
> with strings that are well-defined and not locale-specific (viz. WKT).
> But what is that "something else"? An atof() replacement would be
> doable (if tedious), but printf() would be a major pain to replace...
Indeed, I am not aware of standard non-locale sensitive conversion
functions and alot of code is predicated on sprintf and related.
I have tried implementing something like sprintf() before and it is
hard to do in an efficient (much less correct) manner. How does other
software handle this? It must come up all the time!
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | President OSGF, http://osgeo.org
More information about the Gdal-dev