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 `_MallocPtr'. (You must import `PreludeGlaMisc' to use `_MallocPtr'.)

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

If you use `_MallocPtr', `ghc''s garbage collector will call the user-supplied C function

void FreeMallocPtr( StgMallocPtr garbageMallocPtr )
when the Haskell world can no longer access the object. Since `_MallocPtr'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 :: PrimIO ()


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