[geos-devel] Request for change

Stefan Zschocke s.zschocke at infozoom.de
Wed Mar 1 05:25:48 EST 2006


The const does not make any difference, as the string constructor still is
called.
And the string-ctor does the dynamic memory allocation. 
With the string declaration the texts are actually duplicated in memory:
once as constants and once as static string.
Stefan

-----Original Message-----
From: geos-devel-bounces at geos.refractions.net
[mailto:geos-devel-bounces at geos.refractions.net] On Behalf Of
strk at refractions.net
Sent: Wednesday, March 01, 2006 11:17 AM
To: geos-devel at geos.refractions.net
Subject: Re: [geos-devel] Request for change

Would 'static const string errMsg[]' have the same effect ?

--strk;

On Wed, Mar 01, 2006 at 10:27:53AM +0100, Stefan Zschocke wrote:
> The error messages in TopologyValidationError are currently defined as 
> 	static string errMsg[];
> This causes dynamic memory allocations from std::string ctor. Under 
> certain circumstances, when the Geos.dll is not unloaded before the 
> heap is checked for leaks, these are incorrectly dumped as memory leaks by
VC++.
> When these constants are defined as 
> 	static const char* errMsg[];
> Then this doesn't happen and the heap shows clean. The change requires 
> only changing the type in declaration and implementation without 
> further necessity of code changes.
> Same situation with WBKReader::BAD_GEOM_TYPE_MSG If the declaration is 
> changed to const char*, then a few code changes need to be done:
> Instead of 				
>   throw new ParseException(BAD_GEOM_TYPE_MSG+	" Polygon");
> Make it
>   throw new ParseException(string(BAD_GEOM_TYPE_MSG)+	" Polygon");
> 
> It takes a minute or so to do it, and after that the heap shows clean, 
> which makes it much easer to trace "real" leaks.
> Stefan
_______________________________________________
geos-devel mailing list
geos-devel at geos.refractions.net
http://geos.refractions.net/mailman/listinfo/geos-devel




More information about the geos-devel mailing list