Hi Geoff,

Using the updated code, I encountered another problem. Apparently  
adding the "delete zIn" statement in OBConversion::Read(OBBase* pOb,  
std::istream* pin) breaks a few things.

By deleting the zipstream in the Read() method, it is no longer  
possible to call conv.Read(&mol, &ifs) more than once on a gzipped  
file. At the end of the first call to Read() the zipstream is deleted  
and also the ifstream is closed. So, as long as it possible to get  
more molecules from the input stream the zipstream should not be closed.

Thinking more about this, Read() does not know whether or not the  
ifstream is a new one or if it will be reused or not. So forcing a  
closure on a stream in Read() is probably not the best way forward.  
Furthermore, the way Read() is defined it also means that every time  
you call Read(), the method will check if the input stream is a  
zipstream or not. It seems to me that this causes some significant  
overhead, especially on large files.

I am not completely sure how to fix this, but would it make sense to  
replace  OBConversion::Read(OBBase* pOb, std::istream* pin) with just  
OBConversion::Read(OBBase* pOb) and force developers to use  
SetInStream(std::istream* pin) explicitly before calling  
conv.Read(&mol) and work internally only with pInStream. Checking for  
a zipstream can be then easily handled once within SetInStream(). By  
explicitly setting the streams it will also become easier to keep  
track of them and knowing when to close them.

I am not yet familiar enough with the OpenBabel history and internals  
to assess whether or not such a change would make sense and mean a  
large overhaul of the code.


Gert



On Sep 20, 2010, at 4:48 PM, Geoffrey Hutchison wrote:

>
> On Sep 17, 2010, at 5:21 AM, Gert Thijs wrote:
>
>> To solve the problem with the new zip_istream object created in
>> OBConversion::Convert(istream* is, ostream* os), I have added the
>> following lines at the end of this method
>
> Yes, I agree with this fix. SVN r4065.
>
> Thanks very much,
> -Geoff



------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel

Reply via email to