[geos-devel] Problem with returning Coordinate* from CoordinateList accessor

Martin Davis mbdavis at VividSolutions.com
Fri Nov 15 13:47:01 EST 2002


Good comments...    Your analysis certainly makes sense to me.  And it results in the cleanest, simplest implementation.  

So the two options are:
1. copy the coordinates once at the start of processing and then access them by pointer
2. don't copy the coordinates, but copy them one by one every time they are accessed

It certainly *seems* like #1 should be more efficient in almost all situations.  It's sometimes difficult to predict this kind of thing, however.  When Yury's finished rejigging the code to make the constructors and CoordinateList accessors non-copying, perhaps some more profiling will establish once and for all whether the initial copying of the point lists is a  bottleneck.

Martin Davis, Senior Technical Specialist
Vivid Solutions Inc.
Suite #1A-2328 Government Street   Victoria, B.C.   V8T 5G5
Phone: (250) 385 6040    Fax: (250) 385 6046
EMail: mbdavis at vividsolutions.com  Web: www.vividsolutions.com


> -----Original Message-----
> From: chodgson at refractions.net [mailto:chodgson at refractions.net]
> Sent: Friday, November 15, 2002 10:26 AM
> To: geos-devel at geos.refractions.net
> Subject: Re: [geos-devel] Problem with returning Coordinate* from
> CoordinateList accessor
> 
> 
> Ok, I've been lurking on this list for a while now and I 
> think I'd like to 
> contribute a thought.
> 
> My understanding is that the reason for the "CoordinateList" 
> class is to 
> abstract the underlying data storage. However, the only 
> reason for someone to 
> implement a subclass of coordinate list would be to make use 
> of the complex 
> algorithms that JTS provides - all of which are going to need 
> actual coordinate 
> objects to do their work, no? Perhaps we cannot afford to 
> abstract the the data 
> access layer when our algorithms are going to be doing a LOT 
> of data access.
> 
> It seems to me like it would be more efficient to copy all of 
> one's points into 
> Coordinate objects, once and for all, right at the start (in 
> the CoordinateList 
> constructor). Then, we could pass around references/pointers 
> to the Coordinates 
> without worrying about someone else owning them.
> 
> The only time this would be inefficient, I suppose, is if you 
> were doing a sub-
> linear-time operation... do we do many of those? We could 
> always implement a 
> subclass of coordinate list, with a different underlying data 
> structure, which 
> created the Coordinate objects as they were requested (with 
> gets) and just kept 
> a list of pointers to the Coordinates it allocated, so they 
> could be destroyed 
> when the List was destroyed. It could even be "smart" and 
> cache the Coordinate 
> objects in case they were retrieved again (unlikely to happen 
> much in a sub-
> linear-time operation).
> 
> Just my two cents.
> 
> 
> _______________________________________________
> 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