]> mj.ucw.cz Git - libucw.git/blobdiff - lib/pool.c
CF_USAGE_TAB can be used to insert more tabs to the default help message.
[libucw.git] / lib / pool.c
index b4783e87c46bb7a24fbbd76faf4bf79c321adb08..d581466ba210c87b8a3cb92dea9778a9f78cf259 100644 (file)
@@ -1,13 +1,17 @@
 /*
  *     Sherlock Library -- Memory Pools (One-Time Allocation)
  *
 /*
  *     Sherlock Library -- Memory Pools (One-Time Allocation)
  *
- *     (c) 1997--1999 Martin Mares <mj@ucw.cz>
+ *     (c) 1997--2001 Martin Mares <mj@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
  */
 
 #include "lib/lib.h"
 #include "lib/pools.h"
 
 #include <stdlib.h>
  */
 
 #include "lib/lib.h"
 #include "lib/pools.h"
 
 #include <stdlib.h>
+#include <string.h>
 
 struct memchunk {
   struct memchunk *next;
 
 struct memchunk {
   struct memchunk *next;
@@ -15,7 +19,7 @@ struct memchunk {
 };
 
 struct mempool *
 };
 
 struct mempool *
-new_pool(uns size)
+mp_new(uns size)
 {
   struct mempool *p = xmalloc(sizeof(struct mempool));
 
 {
   struct mempool *p = xmalloc(sizeof(struct mempool));
 
@@ -29,7 +33,7 @@ new_pool(uns size)
 }
 
 void
 }
 
 void
-free_pool(struct mempool *p)
+mp_delete(struct mempool *p)
 {
   struct memchunk *c, *d;
 
 {
   struct memchunk *c, *d;
 
@@ -47,7 +51,7 @@ free_pool(struct mempool *p)
 }
 
 void
 }
 
 void
-flush_pool(struct mempool *p)
+mp_flush(struct mempool *p)
 {
   struct memchunk *c;
 
 {
   struct memchunk *c;
 
@@ -61,7 +65,7 @@ flush_pool(struct mempool *p)
 }
 
 void *
 }
 
 void *
-pool_alloc(struct mempool *p, uns s)
+mp_alloc(struct mempool *p, uns s)
 {
   if (s <= p->threshold)
     {
 {
   if (s <= p->threshold)
     {
@@ -97,3 +101,20 @@ pool_alloc(struct mempool *p, uns s)
       return c->data;
     }
 }
       return c->data;
     }
 }
+
+void *
+mp_alloc_zero(struct mempool *p, uns s)
+{
+  void *x = mp_alloc(p, s);
+  bzero(x, s);
+  return x;
+}
+
+char *
+mp_strdup(struct mempool *p, char *s)
+{
+  uns l = strlen(s) + 1;
+  char *t = mp_alloc_fast_noalign(p, l);
+  memcpy(t, s, l);
+  return t;
+}