Moved definition of nmem_control and nmem_block.
[yaz-moved-to-github.git] / util / nmem.c
index 8fbfd84..ab897c1 100644 (file)
@@ -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.
  *
  *
 
 #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;
 }