X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/c6e5bbae090d043b2e852bb8137bea8e5bca6a6f..573eadb534c42c4feace5e493cc135dd5e7b00d9:/darray.c diff --git a/darray.c b/darray.c index 83150f7..c1ee606 100644 --- a/darray.c +++ b/darray.c @@ -1,6 +1,6 @@ /* -*-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 * @@ -30,6 +30,12 @@ /*----- 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. * @@ -51,6 +57,7 @@ #include #include "alloc.h" +#include "arena.h" #include "darray.h" /*----- Magic numbers -----------------------------------------------------*/ @@ -140,14 +147,14 @@ void *da_ensure(da_base *b, void *v, size_t sz, size_t n) */ 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); } } @@ -246,11 +253,11 @@ void *da_shunt(da_base *b, void *v, size_t sz, size_t n) * 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 --- */ @@ -286,13 +293,13 @@ void *da_tidy(da_base *b, void *v, size_t sz) 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);