projects
/
u
/
mdw
/
catacomb
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
d94f85a
)
Memory allocation counting.
author
mdw
<mdw>
Fri, 10 Dec 1999 23:28:59 +0000
(23:28 +0000)
committer
mdw
<mdw>
Fri, 10 Dec 1999 23:28:59 +0000
(23:28 +0000)
mparena.c
patch
|
blob
|
blame
|
history
mparena.h
patch
|
blob
|
blame
|
history
diff --git
a/mparena.c
b/mparena.c
index
54d9449
..
e7c12cd
100644
(file)
--- a/
mparena.c
+++ b/
mparena.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: mparena.c,v 1.
3 1999/11/22 13:58:00
mdw Exp $
+ * $Id: mparena.c,v 1.
4 1999/12/10 23:28:52
mdw Exp $
*
* Allocation and freeing of MP buffers
*
*
* Allocation and freeing of MP buffers
*
@@
-30,6
+30,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: mparena.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: mparena.c,v $
+ * Revision 1.4 1999/12/10 23:28:52 mdw
+ * Memory allocation counting.
+ *
* Revision 1.3 1999/11/22 13:58:00 mdw
* Document the tweakables.
*
* Revision 1.3 1999/11/22 13:58:00 mdw
* Document the tweakables.
*
@@
-76,7
+79,7
@@
static void *defalloc(mparena *a, size_t sz) { return xmalloc(sz); }
static void deffree(mparena *a, void *p) { free(p); }
static void *defalloc(mparena *a, size_t sz) { return xmalloc(sz); }
static void deffree(mparena *a, void *p) { free(p); }
-mparena_ops mparena_defops = { defalloc, deffree };
+mparena_ops mparena_def
ault
ops = { defalloc, deffree };
/*----- Static variables --------------------------------------------------*/
/*----- Static variables --------------------------------------------------*/
@@
-94,7
+97,7
@@
mparena_ops mparena_defops = { defalloc, deffree };
#endif
#endif
-static mparena arena =
{ 0, &mparena_defops }
;
+static mparena arena =
MPARENA_INIT
;
#define MPARENA_RESOLVE(a) do { \
if ((a) == MPARENA_GLOBAL) \
#define MPARENA_RESOLVE(a) do { \
if ((a) == MPARENA_GLOBAL) \
@@
-142,7
+145,8
@@
static void tdump(mparena_node *n)
void mparena_create(mparena *a)
{
a->root = 0;
void mparena_create(mparena *a)
{
a->root = 0;
- a->ops = &mparena_defops;
+ a->n = 0;
+ a->ops = &mparena_defaultops;
}
/* --- @mparena_setops@ --- *
}
/* --- @mparena_setops@ --- *
@@
-192,6
+196,22
@@
void mparena_destroy(mparena *a)
a->root = 0;
}
a->root = 0;
}
+/* --- @mparena_count@ --- *
+ *
+ * Arguments: @mparena *a@ = pointer to arena block
+ *
+ * Returns: Number of allocated blocks from this arena.
+ *
+ * Use: Reports the number of blocks allocated from the arena and not
+ * yet freed.
+ */
+
+unsigned mparena_count(mparena *a)
+{
+ MPARENA_RESOLVE(a);
+ return (a->n);
+}
+
/* --- @mpalloc@ --- *
*
* Arguments: @mparena *a@ = pointer to arena block
/* --- @mpalloc@ --- *
*
* Arguments: @mparena *a@ = pointer to arena block
@@
-225,8
+245,6
@@
mpw *mpalloc(mparena *a, size_t sz)
MPARENA_OPENFILE;
fprintf(debugfp, "alloc %u\n before: ", sz);
tdump(a->root); putc('\n', debugfp);
MPARENA_OPENFILE;
fprintf(debugfp, "alloc %u\n before: ", sz);
tdump(a->root); putc('\n', debugfp);
- if (sz == 0)
- asm("nop");
#endif
/* --- First, find a block which is big enough --- */
#endif
/* --- First, find a block which is big enough --- */
@@
-239,6
+257,7
@@
again:
#endif
v = a->ops->alloc(a, MPWS(sz + 1));
v[0] = sz;
#endif
v = a->ops->alloc(a, MPWS(sz + 1));
v[0] = sz;
+ a->n++;
return (v + 1);
}
if (n->v[0] < sz) {
return (v + 1);
}
if (n->v[0] < sz) {
@@
-286,6
+305,7
@@
again:
/* --- Get rid of this node now --- */
DESTROY(n);
/* --- Get rid of this node now --- */
DESTROY(n);
+ a->n++;
return (v + 1);
}
return (v + 1);
}
@@
-298,8
+318,7
@@
again:
*
* Returns: ---
*
*
* Returns: ---
*
- * Use: Returns an MP vector to an arena. It doesn't have to be
- * returned to the arena from which it was allocated.
+ * Use: Returns an MP vector to an arena.
*/
#ifdef MPARENA_TRIVIAL
*/
#ifdef MPARENA_TRIVIAL
@@
-338,6
+357,7
@@
void mpfree(mparena *a, mpw *v)
n->left = n->right = 0;
n->v = v;
*nn = n;
n->left = n->right = 0;
n->v = v;
*nn = n;
+ a->n--;
#ifdef MPARENA_DEBUG
fputs(" after: ", debugfp);
#ifdef MPARENA_DEBUG
fputs(" after: ", debugfp);
diff --git
a/mparena.h
b/mparena.h
index
61c735e
..
b541b25
100644
(file)
--- a/
mparena.h
+++ b/
mparena.h
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: mparena.h,v 1.
1 1999/11/17 18:02:16
mdw Exp $
+ * $Id: mparena.h,v 1.
2 1999/12/10 23:28:59
mdw Exp $
*
* Allocation and freeing of MP buffers
*
*
* Allocation and freeing of MP buffers
*
@@
-30,13
+30,16
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: mparena.h,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: mparena.h,v $
+ * Revision 1.2 1999/12/10 23:28:59 mdw
+ * Memory allocation counting.
+ *
* Revision 1.1 1999/11/17 18:02:16 mdw
* New multiprecision integer arithmetic suite.
*
*/
* Revision 1.1 1999/11/17 18:02:16 mdw
* New multiprecision integer arithmetic suite.
*
*/
-#ifndef MPARENA_H
-#define MPARENA_H
+#ifndef
CATACOMB_
MPARENA_H
+#define
CATACOMB_
MPARENA_H
#ifdef __cplusplus
extern "C" {
#ifdef __cplusplus
extern "C" {
@@
-44,7
+47,7
@@
/*----- Header files ------------------------------------------------------*/
/*----- Header files ------------------------------------------------------*/
-#ifndef MPW_H
+#ifndef
CATACOMB_
MPW_H
# include "mpw.h"
#endif
# include "mpw.h"
#endif
@@
-68,6
+71,7
@@
typedef struct mparena_node {
typedef struct mparena {
mparena_node *root;
typedef struct mparena {
mparena_node *root;
+ unsigned n;
struct mparena_ops *ops;
} mparena;
struct mparena_ops *ops;
} mparena;
@@
-105,7
+109,7
@@
extern mparena_ops mparena_defaultops;
extern void mparena_create(mparena */*a*/);
extern void mparena_create(mparena */*a*/);
-#define MPARENA_INIT { 0, &mparena_defaultops }
+#define MPARENA_INIT { 0,
0,
&mparena_defaultops }
/* --- @mparena_setops@ --- *
*
/* --- @mparena_setops@ --- *
*
@@
-132,6
+136,18
@@
extern mparena_ops *mparena_setops(mparena */*a*/, mparena_ops */*ops*/);
extern void mparena_destroy(mparena */*a*/);
extern void mparena_destroy(mparena */*a*/);
+/* --- @mparena_count@ --- *
+ *
+ * Arguments: @mparena *a@ = pointer to arena block
+ *
+ * Returns: Number of allocated blocks from this arena.
+ *
+ * Use: Reports the number of blocks allocated from the arena and not
+ * yet freed.
+ */
+
+extern unsigned mparena_count(mparena */*a*/);
+
/* --- @mpalloc@ --- *
*
* Arguments: @mparena *a@ = pointer to arena block
/* --- @mpalloc@ --- *
*
* Arguments: @mparena *a@ = pointer to arena block
@@
-152,8
+168,7
@@
extern mpw *mpalloc(mparena */*a*/, size_t /*sz*/);
*
* Returns: ---
*
*
* Returns: ---
*
- * Use: Returns an MP vector to an arena. It doesn't have to be
- * returned to the arena from which it was allocated.
+ * Use: Returns an MP vector to an arena.
*/
extern void mpfree(mparena */*a*/, mpw */*v*/);
*/
extern void mpfree(mparena */*a*/, mpw */*v*/);