[Gdal-dev] OGR Close Datasource?

Frank Warmerdam warmerdam at pobox.com
Wed Sep 21 09:35:56 EDT 2005


On 9/21/05, Charlie Savage <cfis at interserv.com> wrote:
> Wondering if it would make sense to introduce the concept of "closing" a
> datasource to the OGR API as a distinct thing from "destroying" a data
> source object?
>
> I bring this up because I run into a problem with a test script in Ruby:
>
> 1.  Create temporary csv data source
> 2.  Do some stuff to it
> 3.  At the end of the test, delete the temporary data source

Charlie,

I am guessing that you want an explicit concept of Close() on the
C++ OGRDataSource object, is that right?  That is, close the datasource
regardless of how many references exist on it.  The problem I have with
this is that closing in all the drivers is currently accomplished in the
datasource destructors and so it would be a bit job to change all the
drivers to a separate Close() method.  Especially since then ideally
the datasource object would gracefully error out in case of accesses
to a closed data source.

So, I am against changing the core to include a Close() method.

However, I don't mind adding a Close() method in ogr.i that just
decrements the datasource reference count, and destroys it if
it has dropped to zero.  The downside of this approach is that any
other variables referring to the datasource that haven't been garbage
collected will still have a reference and hold open the datasource.

Sorry...

PS. In answer to Ari's point, on unix the Destroy method may have
unlinked files for a datasource but if they are still open they aren't
really deleted.  Behavior is different on win32 where unlinking an
in use file will fail.  Generally speaking you should not have a datasource
open when destroying it as results are undefined.

Best regards,
--
---------------------------------------+--------------------------------------
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    | Geospatial Programmer for Rent




More information about the Gdal-dev mailing list