[project @ 1998-11-26 09:17:22 by sof]
[ghc-hetmet.git] / ghc / runtime / main / Mallocs.lc
1 %---------------------------------------------------------------*
2 %
3 \section{Wrappers around malloc}
4 %
5 %---------------------------------------------------------------*
6
7 Routines that deal with memory allocation:
8
9 A LONG-AGO WISH: All dynamic allocation must be done before the stacks
10 and heap are allocated. This allows us to use the lower level sbrk
11 routines if required.
12
13 ANOTHER ONE: Should allow use of valloc to align on page boundary.
14
15 \begin{code}
16 #include "rtsdefs.h"
17
18 char *
19 stgMallocBytes(n, msg)
20   I_   n;
21   char *msg;
22 {
23     char *space;
24
25     if ((space = (char *) malloc((size_t) n)) == NULL) {
26         fflush(stdout);
27         MallocFailHook((W_) n, msg); /*msg*/
28         EXIT(EXIT_FAILURE);
29     }
30     return space;
31 }
32
33 char *
34 stgMallocWords(n, msg)
35   I_   n;
36   char *msg;
37 {
38   return(stgMallocBytes(n * sizeof(W_), msg));
39 }
40 \end{code}