/* -*-c-*-
*
- * $Id: darray.c,v 1.4 1999/11/06 12:40:45 mdw Exp $
+ * $Id: darray.c,v 1.6 2000/07/16 12:29:16 mdw Exp $
*
* Dynamically growing dense arrays
*
/*----- Revision history --------------------------------------------------*
*
* $Log: darray.c,v $
+ * Revision 1.6 2000/07/16 12:29:16 mdw
+ * Change to arena `realloc' interface, to fix a design bug.
+ *
+ * Revision 1.5 2000/06/17 10:37:39 mdw
+ * Add support for arena management.
+ *
* Revision 1.4 1999/11/06 12:40:45 mdw
* Minor changes to allocation strategy.
*
#include <stdlib.h>
#include "alloc.h"
+#include "arena.h"
#include "darray.h"
/*----- Magic numbers -----------------------------------------------------*/
*/
if (p && slots == b->off) {
- q = xrealloc(p - b->off * sz, nsz * sz);
+ q = x_realloc(b->a, p - b->off * sz, nsz * sz, b->sz + b->off);
q += slots * sz;
} else {
- q = xmalloc(nsz * sz);
+ q = x_alloc(b->a, nsz * sz);
q += slots * sz;
if (p) {
memcpy(q, p, b->len * sz);
- free(p - b->off * sz);
+ x_free(b->a, p - b->off * sz);
}
}
* almost all the time -- that's the whole point of this routine!
*/
- q = xmalloc(nsz * sz);
+ q = x_alloc(b->a, nsz * sz);
q += (nsz - slots) * sz;
if (p) {
memcpy(q, p, b->len * sz);
- free(p - b->off * sz);
+ x_free(b->a, p - b->off * sz);
}
/* --- Fill in the other parts of the base structure --- */
return (p);
if (!b->len) {
- free(p - b->off * sz);
+ xfree(p - b->off * sz);
return (0);
}
- q = xmalloc(b->len * sz);
+ q = x_alloc(b->a, b->len * sz);
memcpy(q, p, b->len * sz);
- free(p - b->off * sz);
+ x_free(b->a, p - b->off * sz);
b->sz = b->len;
b->off = 0;
return (q);