7 * These are interface routines to be placed between a program and the
8 * system memory allocator.
10 * It forces well-defined semantics for several 'borderline' cases:
12 * malloc() of a 0 size object is guaranteed to return something
13 * which is not 0, and can safely be freed (but not dereferenced)
14 * free() accepts (silently) an 0 pointer
15 * realloc of a 0 pointer is allowed, and is equiv. to malloc()
16 * For the IBM/PC it forces no object > 64K; note that the size argument
17 * to malloc/realloc is a 'long' to catch this condition
19 * The function pointer MMoutOfMemory() contains a vector to handle a
20 * 'out-of-memory' error (which, by default, points at a simple wrap-up
28 extern char *MMalloc(long);
29 extern void MMout_of_memory(long);
30 extern char *MMrealloc(char *, long);
32 void (*MMoutOfMemory
)(long) = MMout_of_memory
;
39 /* MMout_of_memory -- out of memory for lazy people, flush and exit */
41 MMout_of_memory(long size
)
43 (void) fflush(stdout
);
44 (void) fprintf(stderr
, "\nout of memory allocating %lu bytes\n",
45 (unsigned long) size
);
57 if (MMoutOfMemory
!= (void (*)(long)) 0 ) (*MMoutOfMemory
)(size
);
61 if (size
== 0) size
= sizeof(long);
62 if ((p
= (char *) malloc((unsigned long) size
)) == NIL(char)) {
63 if (MMoutOfMemory
!= 0 ) (*MMoutOfMemory
)(size
);
71 MMrealloc(char *obj
, long size
)
77 if (MMoutOfMemory
!= 0 ) (*MMoutOfMemory
)(size
);
81 if (obj
== NIL(char)) return MMalloc(size
);
82 if (size
<= 0) size
= sizeof(long);
83 if ((p
= (char *) realloc(obj
, (unsigned long) size
)) == NIL(char)) {
84 if (MMoutOfMemory
!= 0 ) (*MMoutOfMemory
)(size
);