forwarding a radium compilation fix.
[AROS-Contrib.git] / arospdf / goo / gmem.h
blobda34736f2163e5ce57900ddfb980c6c27992487d
1 /*
2 * gmem.h
4 * Memory routines with out-of-memory checking.
6 * Copyright 1996-2003 Glyph & Cog, LLC
7 */
9 #ifndef GMEM_H
10 #define GMEM_H
12 #include <stdio.h>
13 #include <aconf.h>
15 #if USE_EXCEPTIONS
17 class GMemException {
18 public:
19 GMemException() {}
20 ~GMemException() {}
23 #define GMEM_EXCEP throw(GMemException)
25 #else // USE_EXCEPTIONS
27 #define GMEM_EXCEP
29 #endif // USE_EXCEPTIONS
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
36 * Same as malloc, but prints error message and exits if malloc()
37 * returns NULL.
39 extern void *gmalloc(int size) GMEM_EXCEP;
42 * Same as realloc, but prints error message and exits if realloc()
43 * returns NULL. If <p> is NULL, calls malloc instead of realloc().
45 extern void *grealloc(void *p, int size) GMEM_EXCEP;
48 * These are similar to gmalloc and grealloc, but take an object count
49 * and size. The result is similar to allocating nObjs * objSize
50 * bytes, but there is an additional error check that the total size
51 * doesn't overflow an int.
53 extern void *gmallocn(int nObjs, int objSize) GMEM_EXCEP;
54 extern void *greallocn(void *p, int nObjs, int objSize) GMEM_EXCEP;
57 * Same as free, but checks for and ignores NULL pointers.
59 extern void gfree(void *p);
61 #ifdef DEBUG_MEM
63 * Report on unfreed memory.
65 extern void gMemReport(FILE *f);
66 #else
67 #define gMemReport(f)
68 #endif
71 * Allocate memory and copy a string into it.
73 extern char *copyString(char *s);
75 #ifdef __cplusplus
77 #endif
79 #endif