/*
- * $Id: util.c,v 1.8 1996/07/09 03:41:14 wessels Exp $
+ * $Id: util.c,v 1.9 1996/07/12 17:38:11 wessels Exp $
*
* DEBUG:
* AUTHOR: Harvest Derived
#if XMALLOC_DEBUG
-#define DBG_ARRY_SZ (2<<8)
-#define DBG_ARRY_BKTS (2<<8)
+#define DBG_ARRY_SZ (1<<10)
+#define DBG_ARRY_BKTS (1<<8)
static void *malloc_ptrs[DBG_ARRY_BKTS][DBG_ARRY_SZ];
static int malloc_size[DBG_ARRY_BKTS][DBG_ARRY_SZ];
static int dbg_initd = 0;
static void check_init()
{
- for (B = 0; B < DBG_ARRY_SZ; B++) {
+ for (B = 0; B < DBG_ARRY_BKTS; B++) {
for (I = 0; I < DBG_ARRY_SZ; I++) {
malloc_ptrs[B][I] = NULL;
malloc_size[B][I] = 0;
}
#endif
+#ifdef XMALLOC_COUNT
+static void xmalloc_count(p, sign)
+ void *p;
+ int sign;
+{
+ size_t sz;
+ static size_t total = 0;
+ int memoryAccounted();
+ int mallinfoTotal();
+ sz = mallocblksize(p) * sign;
+ total += sz;
+ fprintf(stderr, "xmalloc_count=%9d accounted=%9d mallinfo=%9d\n",
+ (int) total,
+ memoryAccounted(),
+ mallinfoTotal());
+}
+#endif /* XMALLOC_COUNT */
+
/*
* xmalloc() - same as malloc(3). Used for portability.
* Never returns NULL; fatal on error.
#endif
#if XMALLOC_STATISTICS
malloc_stat(sz);
+#endif
+#if XMALLOC_COUNT
+ xmalloc_count(p, 1);
#endif
return (p);
}
{
#if XMALLOC_DEBUG
check_free(s);
+#endif
+#if XMALLOC_COUNT
+ xmalloc_count(s, -1);
#endif
if (s != NULL)
free(s);
{
#if XMALLOC_DEBUG
check_free(s);
+#endif
+#if XMALLOC_COUNT
+ xmalloc_count(s, -1);
#endif
free(s);
}
{
static void *p;
+#if XMALLOC_COUNT
+ xmalloc_count(s, -1);
+#endif
+
if (sz < 1)
sz = 1;
if ((p = realloc(s, sz)) == NULL) {
#endif
#if XMALLOC_STATISTICS
malloc_stat(sz);
+#endif
+#if XMALLOC_COUNT
+ xmalloc_count(p, 1);
#endif
return (p);
}
#endif
#if XMALLOC_STATISTICS
malloc_stat(sz);
+#endif
+#if XMALLOC_COUNT
+ xmalloc_count(p, 1);
#endif
return (p);
}