[postgis-devel] Re: [geos-devel] Finding the Leak
Mateusz Loskot
mateusz at loskot.net
Tue Aug 19 05:04:31 PDT 2008
Paul Ramsey wrote:
> I was thinking that the blunt-force solution would be to clone the
> Geometry when PreparedGeometry is constructed, rather than retaining a
> reference, so we an delete the whole kit-n-kaboodle when we're done
> with the PreparedGeometry.
Paul,
I agree it would solve the lack of RAII in current version.
However, personally I'd not be happy with that solution :-)
PreparedGeometry stuff is supposed to optimize [1] certain spatial
operations. Making a deep copy of geometries, often huge and complex, is
expansive. I presume copying op would countervail the potential gain of
efficiency we want to benefit from prepared geometry concept.
I understand (and I agree) that better is the enemy of good, however
at the same time I believe that a makeshift is the enemy of good :-)
So, I can't resist the temptation of proposing and trying to improve GEOS.
Back to the reality, I understand we lack of manpower, but perhaps we
could try to relax the requirements a little :-)
For example, why not to allow PreparedGeometry to outlive the Geometry
but in safe way - PG is notified that Geometry has expired.
It should be easily achieved with help of two idioms:
1) shared resources
2) weak reference.
Talking of examples, the former is available as boost::shared_ptr and
the latter boost::weak_ptr. Here is a good intro to these concepts [2]
I am trying to convince to use Boost and make it a new dependency for
GEOS. I just use it as an example of very well-thought implementations
of the concepts discussed above. Though, it's not a secret it would be
easier to actually use Boost :-)
[1]
http://lin-ear-th-inking.blogspot.com/2007/08/preparedgeometry-efficient-batch.html
[2] http://www.ddj.com/cpp/184402026
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
More information about the postgis-devel
mailing list