X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/8c6d948bbb87df8f1ffb49d3af1419b84ea34a0e..ee9b1404a97247490a09fcf10af83a76a3d3d72d:/sub.c diff --git a/sub.c b/sub.c index bb264a2..57ee194 100644 --- a/sub.c +++ b/sub.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: sub.c,v 1.4 1999/05/13 22:48:55 mdw Exp $ + * $Id: sub.c,v 1.5 1999/05/19 20:27:11 mdw Exp $ * * Allocation of known-size blocks * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: sub.c,v $ + * Revision 1.5 1999/05/19 20:27:11 mdw + * Change naming to match newer mLib conventions. + * * Revision 1.4 1999/05/13 22:48:55 mdw * Change `-ise' to `-ize' throughout. * @@ -134,8 +137,8 @@ /*----- Static variables --------------------------------------------------*/ -static void *sub__bins[SUB_BINS]; -static size_t sub__sizes[SUB_BINS]; +static void *bins[SUB_BINS]; +static size_t sizes[SUB_BINS]; /*----- Main code ---------------------------------------------------------*/ @@ -161,11 +164,11 @@ void *sub_alloc(size_t s) /* --- If the bin is empty, find some memory --- */ - if (!sub__bins[bin]) { + if (!bins[bin]) { char *p, *q; - p = xmalloc(sub__sizes[bin]); - q = p + sub__sizes[bin]; + p = xmalloc(sizes[bin]); + q = p + sizes[bin]; s = SUB_BINSZ(bin); @@ -177,13 +180,13 @@ void *sub_alloc(size_t s) *(void **)q = q + s; } - sub__bins[bin] = p; + bins[bin] = p; } /* --- Extract the first block in the list --- */ - p = sub__bins[bin]; - sub__bins[bin] = *(void **)p; + p = bins[bin]; + bins[bin] = *(void **)p; return (p); } @@ -204,8 +207,8 @@ void sub_free(void *p, size_t s) if (bin >= SUB_BINS) free(p); else { - *(void **)p = sub__bins[bin]; - sub__bins[bin] = p; + *(void **)p = bins[bin]; + bins[bin] = p; } } @@ -225,7 +228,7 @@ void sub_init(void) /* --- Initialize the sizes bins --- */ for (i = 1; i < SUB_BINS; i++) { - sub__sizes[i] = ((SUB_CHUNK + SUB_BINSZ(i) - 1) / + sizes[i] = ((SUB_CHUNK + SUB_BINSZ(i) - 1) / SUB_BINSZ(i) * SUB_BINSZ(i)); } }