[geos-devel] GeometryFactory - call for explanation

Charlie Savage cfis at interserv.com
Thu Mar 30 20:20:58 EST 2006


While on the subject of geometry factories....

Would it be possible to add a global, default factory?  This would be 
very helpful when accessing GEOS from scripting languages like ruby and 
python.

The first issue it would solve is worrying about keeping geometry 
factories alive for longer than the geometries themselves.  This is 
tricker than it sounds because at least in Ruby you're dealing with a 
mark and sweep garbage collector.  So what I do in Ruby is create a 
global factory and always use that.

However, that solution breaks down when dealing with marshaling 
objects.  Ruby has the concept of marshal/unmarshal like a lot of other 
languages.  Since GEOS is in C, these methods need to be implemented in 
C++ (as part of the SWIG bindings).  Thus, since I'm in C++ I don't have 
easy access to the geometry factory I created on the Ruby side.  Thus in 
C++ I can create a GeometryFactory as a global of some sort fully 
realizing it will never be freed and thus leak memory.  The alternative 
is worse, create the factory, create the geometry, free the factory, get 
a segmentation fault.  For the moment, I go with a static variable in 
the SWIG bindings...would be nice to get something like this officially 
supported.

Of course, removing the dependency between geometries and factories 
would be even better.  I have no idea if its possible since I haven't 
looked at that part of the code - but it is a bit annoying having the 
back reference from geometries to factories to have to worry about.

Charlie


Mateusz Łoskot wrote:
> Hi,
>
> Could anyone explain/confirm me assumptions behind
> the GeometryFactory class?
> Depending on its semantic I'd have some proposal to refactor it.
> Here are my qusetions:
>
> Are following assumptions correct?
>
> 1. Ever instance of Geometry type (or its subtype) can have assigned its
> own instance of GeometryFactory
>
> 2. One instance of GeometryFactory class can be shared (assigned to)
> between more than one objects of Geometry class
>
> 3. It is not assumed that all geometries share the same
> common instance of GeometryFactory
>
> Thanks in advance for comments
> Cheers
>   
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3166 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.osgeo.org/pipermail/geos-devel/attachments/20060330/8dd98ba3/smime.bin


More information about the geos-devel mailing list