X-Git-Url: https://git.distorted.org.uk/~mdw/mLib/blobdiff_plain/f1583053728612927421802c7a9040c8fb3e2a51..f8509853f72daec365373f9d8c18f63cf8bad54e:/darray.c diff --git a/darray.c b/darray.c index 0825bca..bee6955 100644 --- a/darray.c +++ b/darray.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: darray.c,v 1.1 1999/10/22 22:37:26 mdw Exp $ + * $Id: darray.c,v 1.2 1999/10/28 22:05:28 mdw Exp $ * * Dynamically growing dense arrays * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: darray.c,v $ + * 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'. * @@ -46,7 +49,7 @@ /*----- Magic numbers -----------------------------------------------------*/ -#define DA_INITSZ 64 /* Default size for new array */ +#define DA_INITSZ 16 /* Default size for new array */ #define DA_SLOTS 8 /* Number of preshifted slots */ /*----- Main code ---------------------------------------------------------*/ @@ -114,7 +117,7 @@ void *da_ensure(da_base *b, void *v, size_t sz, size_t n) /* --- Reallocate the array --- */ - nsz = v ? b->sz + b->off : DA_INITSZ; + nsz = v ? b->sz + b->off : (DA_INITSZ >> 1); do nsz <<= 1; while (nsz < rq); q = xmalloc(nsz * sz); q += slots * sz; @@ -193,7 +196,7 @@ void *da_shunt(da_base *b, void *v, size_t sz, size_t n) /* --- Reallocate the array --- */ - nsz = v ? b->sz + b->off : DA_INITSZ; + nsz = v ? b->sz + b->off : (DA_INITSZ >> 1); do nsz <<= 1; while (nsz < rq); q = xmalloc(nsz * sz); q += (nsz - slots) * sz;