]> mj.ucw.cz Git - libucw.git/blobdiff - lib/pool.c
Introduced obuck_get_pos(), converted gatherd limits to use it.
[libucw.git] / lib / pool.c
index a7d6f5b0fd0b1c65faef6afe2d3fbc1efa5620f4..4eea7bf700f8e0ab0981bd22c0f2b3933050f546 100644 (file)
@@ -1,13 +1,14 @@
 /*
  *     Sherlock Library -- Memory Pools (One-Time Allocation)
  *
- *     (c) 1997--1999 Martin Mares <mj@ucw.cz>
+ *     (c) 1997--2001 Martin Mares <mj@ucw.cz>
  */
 
 #include "lib/lib.h"
 #include "lib/pools.h"
 
 #include <stdlib.h>
+#include <string.h>
 
 struct memchunk {
   struct memchunk *next;
@@ -15,7 +16,7 @@ struct memchunk {
 };
 
 struct mempool *
-new_pool(uns size)
+mp_new(uns size)
 {
   struct mempool *p = xmalloc(sizeof(struct mempool));
 
@@ -29,25 +30,25 @@ new_pool(uns size)
 }
 
 void
-free_pool(struct mempool *p)
+mp_delete(struct mempool *p)
 {
   struct memchunk *c, *d;
 
   for(d=p->first; d; d = c)
     {
       c = d->next;
-      free(d);
+      xfree(d);
     }
   for(d=p->first_large; d; d = c)
     {
       c = d->next;
-      free(d);
+      xfree(d);
     }
-  free(p);
+  xfree(p);
 }
 
 void
-flush_pool(struct mempool *p)
+mp_flush(struct mempool *p)
 {
   struct memchunk *c;
 
@@ -56,12 +57,12 @@ flush_pool(struct mempool *p)
   while (c = p->first_large)
     {
       p->first_large = c->next;
-      free(c);
+      xfree(c);
     }
 }
 
 void *
-pool_alloc(struct mempool *p, uns s)
+mp_alloc(struct mempool *p, uns s)
 {
   if (s <= p->threshold)
     {
@@ -97,3 +98,11 @@ pool_alloc(struct mempool *p, uns s)
       return c->data;
     }
 }
+
+void *
+mp_alloc_zero(struct mempool *p, uns s)
+{
+  void *x = mp_alloc(p, s);
+  bzero(x, s);
+  return x;
+}