X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=util%2Fnmem.c;h=ab897c1f3388c587b68d36dda2709bf8fb0a8b86;hb=113640450c45ca7ac96285cc8ca666bfd597ed21;hp=8fbfd841140af25231dacbe7b6f60bb7695ff023;hpb=a309d6ece06c0ab732d98c59f2718efaebd01ec6;p=yaz-moved-to-github.git diff --git a/util/nmem.c b/util/nmem.c index 8fbfd84..ab897c1 100644 --- a/util/nmem.c +++ b/util/nmem.c @@ -1,10 +1,16 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1997, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: nmem.c,v $ - * Revision 1.1 1995-11-13 09:27:52 quinn + * Revision 1.3 1997-07-21 12:47:38 adam + * Moved definition of nmem_control and nmem_block. + * + * Revision 1.2 1995/12/13 13:44:37 quinn + * Modified Data1-system to use nmem + * + * Revision 1.1 1995/11/13 09:27:52 quinn * Fiddling with the variant stuff. * * @@ -20,21 +26,8 @@ #define NMEM_CHUNK (10*1024) -typedef struct nmem_block -{ - char *buf; /* memory allocated in this block */ - int size; /* size of buf */ - int top; /* top of buffer */ - struct nmem_block *next; -} nmem_block; - -typedef struct nmem_control -{ - int total; - nmem_block *blocks; -} nmem_control; - -static nmem_block *freelist = 0; /* global freelist */ +static nmem_block *freelist = 0; /* global freelists */ +static nmem_control *cfreelist = 0; static void free_block(nmem_block *p) { @@ -113,10 +106,15 @@ int nmem_total(NMEM n) NMEM nmem_create(void) { - NMEM r = xmalloc(sizeof(*r)); + NMEM r = cfreelist; + if (r) + cfreelist = cfreelist->next; + else + r = xmalloc(sizeof(*r)); r->blocks = 0; r->total = 0; + r->next = 0; return r; } @@ -125,5 +123,6 @@ void nmem_destroy(NMEM n) if (!n) return; nmem_reset(n); - xfree(n); + n->next = cfreelist; + cfreelist = n; }