2 * UCW Library -- Memory Pools
4 * (c) 1997--2005 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
14 #define POOL_ALIGN CPU_STRUCT_ALIGN
19 struct memchunk *first, *current, **plast;
20 struct memchunk *first_large;
21 uns chunk_size, threshold;
24 struct mempool *mp_new(uns);
25 void mp_delete(struct mempool *);
26 void mp_flush(struct mempool *);
27 void *mp_alloc(struct mempool *, uns);
28 void *mp_alloc_zero(struct mempool *, uns);
30 static inline void *mp_alloc_fast(struct mempool *p, uns l)
32 byte *f = (void *) (((addr_int_t) p->free + POOL_ALIGN - 1) & ~(addr_int_t)(POOL_ALIGN - 1));
35 return mp_alloc(p, l);
40 static inline void *mp_alloc_fast_noalign(struct mempool *p, uns l)
45 return mp_alloc(p, l);
51 mp_start_string(struct mempool *p, uns l)
53 ASSERT(l <= p->chunk_size);
54 return mp_alloc(p, l);
58 mp_end_string(struct mempool *p, void *stop)
65 char *mp_strdup(struct mempool *, char *);
66 void *mp_memdup(struct mempool *, void *, uns);
67 char *mp_multicat(struct mempool *, ...);
69 mp_strcat(struct mempool *mp, char *x, char *y)
71 return mp_multicat(mp, x, y, NULL);
76 char *mp_printf(struct mempool *p, char *fmt, ...) FORMAT_CHECK(printf,2,3);
77 char *mp_vprintf(struct mempool *p, char *fmt, va_list args);