Go to the first, previous, next, last section, table of contents.

Pointing outside the Haskell heap

There are two types that `ghc' programs can use to reference (heap-allocated) objects outside the Haskell world: `Addr' and `ForeignObj'.

If you use `Addr', it is up to you to the programmer to arrange allocation and deallocation of the objects.

If you use `ForeignObj', `ghc''s garbage collector will call upon the user-supplied finaliser function to free the object when the Haskell world no longer can access the object. (An object is associated with a finaliser function when the abstract Haskell type `ForeignObj' is created). The finaliser function is expressed in C, and is passed as argument the object:

void foreignFinaliser ( StgForeignObj fo )
when the Haskell world can no longer access the object. Since `ForeignObj's only get released when a garbage collection occurs, we provide ways of triggering a garbage collection from within C and from within Haskell.
void StgPerformGarbageCollection()
performGC :: IO ()

More information is provided on the programmers' interface to `ForeignObj' can be found in Section See section Foreign objects.


Go to the first, previous, next, last section, table of contents.