[Haskell-cafe] FFI and modifying haskell memory
Sven.Panne at aedion.de
Sat Oct 29 11:35:10 EDT 2005
Am Samstag, 29. Oktober 2005 14:27 schrieb Joel Reymont:
> So both with and allocaBytes allocate bytes on the stack then, correct?
It depends on what you mean by "stack". :-) From a conceptual point of view,
both pass a pointer to a temporary memory region to a given action *which is
only valid during the execution of the action*, so it would be incorrect to
if the pointer somehow "escapes" the action.
How this temporary memory is actually allocated depends on the implementation:
Hugs and NHC use malloc/free, ensuring that free is even called in case of an
exception, so that there will be no space leaks. GHC does something more
efficient by allocating the memory from the normal Haskell runtime heap, but
ensuring that the memory is never moved by garbage collection. This is called
"pinned memory" sometimes, see e.g. Java's JNI.
More information about the Haskell-Cafe