*
* Memory routines with out-of-memory checking.
*
- * Copyright 1996-2002 Glyph & Cog, LLC
+ * Copyright 1996-2003 Glyph & Cog, LLC
*/
#include <aconf.h>
static int gMemIndex = 0;
static int gMemAlloc = 0;
+static int gMemInUse = 0;
#endif /* DEBUG_MEM */
hdr->next = gMemList[lst];
gMemList[lst] = hdr;
++gMemAlloc;
+ gMemInUse += size;
for (p = (unsigned long *)data; p <= trl; ++p)
*p = gMemDeadVal;
return data;
#endif
}
+void *gmallocn(int nObjs, int objSize) {
+ int n;
+
+ n = nObjs * objSize;
+ if (objSize == 0 || n / objSize != nObjs) {
+ fprintf(stderr, "Bogus memory allocation size\n");
+ exit(1);
+ }
+ return gmalloc(n);
+}
+
+void *greallocn(void *p, int nObjs, int objSize) {
+ int n;
+
+ n = nObjs * objSize;
+ if (objSize == 0 || n / objSize != nObjs) {
+ fprintf(stderr, "Bogus memory allocation size\n");
+ exit(1);
+ }
+ return grealloc(p, n);
+}
+
void gfree(void *p) {
#ifdef DEBUG_MEM
int size;
else
gMemList[lst] = hdr->next;
--gMemAlloc;
+ gMemInUse -= hdr->size;
size = gMemDataSize(hdr->size);
trl = (unsigned long *)((char *)hdr + gMemHdrSize + size);
if (*trl != gMemDeadVal) {