% % % (c) The GRASP/AQUA Project, Glasgow University, 1998 % \subsection[allocMem.lc]{Allocating memory off heap} \begin{code} #include "rtsdefs.h" #include "stgio.h" StgAddr allocMemory__(sz) StgInt sz;/* bytes*/ { StgAddr ptr; if ( (ptr = malloc(sz*sizeof(char))) == NULL) { ghc_errtype = ERR_RESOURCEEXHAUSTED; ghc_errstr = "malloc failed"; return NULL; } return ptr; } \end{code}