RE: Allocation & Marshalling Question (again)
Judging by the silence that greeted my last posts re this a couple of weeks ago I suspect this is of no interest to anyone but me :-(
An extra couple of weeks cogitation on this hasn't really changed MHO much (other than I'm no longer so pessimistic about the safety of my <+ operator).
Seeing as the FFI seems to be close to finalization I thought I'd have another go. So excuse me if this seems half baked, but am I the only one who thinks the type signatures of utilities like this.. allocaBytes :: Int -> (Ptr a -> IO b) -> IO b ..are rather inconvenient?
Wouldn't.. allocaBytes :: Int -> (Ptr a -> b) -> b ..be more useful?
I haven't thought about this too hard, but it seems "technically difficult" if not "technically impossible". In an implementation which uses a foreign call to malloc to implement allocaBytes, then there has to be a reliable way to ensure that the memory is deallocated later. If we're not in the IO monad, then I can't see how to do this. Even in GHC where we use garbage collected memory instead of malloc, we still make use of the IO monad to control the lifetime of the allocated memory. Cheers, Simon
On Wednesday 28 May 2003 10:32, Simon Marlow wrote:
Even in GHC where we use garbage collected memory instead of malloc, we still make use of the IO monad to control the lifetime of the allocated memory.
Thanks for that info. I'm not to clear about what the intended implementation is (if there is one) from reading the FFI spec. It seems to me that if the IO monad is used to control the lifetime you could use stack allocation quite easily. (Dunno if that would be any more efficient for the ghc rts though.) Using the garbage collected heap but not actually using normal garbage collection mechanisms seems a bit strange to me :-) Regards -- Adrian Hey
participants (2)
-
Adrian Hey -
Simon Marlow