Wed, 14 Mar 2001 10:37:04 +1100, Manuel M. T. Chakravarty <[EMAIL PROTECTED]> pisze: > > Add 'destruct :: Ptr a -> IO ()' method to class Storable. Thanks > > Wojciech Moczydlowski <[EMAIL PROTECTED]> for the suggestion. > > Is this supposed to be a GHC-only extension of the FFI libraries? > If not, why didn't we discuss it - or did I miss something? Sorry, I should have discussed it. In the Storable instance of a C struct sometimes poke wants to allocate additional memory. E.g. the struct contains char* which corresponds to String in Haskell. It must be freed somewhere. Usually poke is idempotent, but in this case it's not. There is always a well-defined piece of code derived from what poke does, corresponding to C++'s destructor. There was no good place to put it. It should be called by withObject / withArray functions (I'm going to finish it), and sometimes explicitly before free. Storable is IMHO a very good place. This method has a default definition, so you can forget about it when using Storable for trivial types. Any objections? If not, I'm going to add also destructArray and destructArray0 to MarshalArray, and lengthArray0 while I am at it (it was used internally so it makes sense to be provided separately), and document it. -- __("< Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTÊPCZA QRCZAK _______________________________________________ FFI mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/ffi