/* -*-c-*-
*
- * $Id: darray.c,v 1.4 1999/11/06 12:40:45 mdw Exp $
+ * $Id: darray.c,v 1.7 2004/04/08 01:36:11 mdw Exp $
*
* Dynamically growing dense arrays
*
* MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: darray.c,v $
- * Revision 1.4 1999/11/06 12:40:45 mdw
- * Minor changes to allocation strategy.
- *
- * Revision 1.3 1999/10/29 22:59:22 mdw
- * New array adjustment macros for unsigned arguments.
- *
- * Revision 1.2 1999/10/28 22:05:28 mdw
- * Modify and debug allocation routines.
- *
- * Revision 1.1 1999/10/22 22:37:26 mdw
- * New dynamic array implementation replaces `dynarray.h'.
- *
- */
-
/*----- Header files ------------------------------------------------------*/
#include <stdio.h>
#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);