2 * Sherlock Library -- Memory Pools (One-Time Allocation)
4 * (c) 1997--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
14 struct memchunk *next;
21 struct mempool *p = xmalloc(sizeof(struct mempool));
23 size -= sizeof(struct memchunk);
24 p->free = p->last = NULL;
25 p->first = p->current = p->first_large = NULL;
28 p->threshold = size / 3;
33 free_pool(struct mempool *p)
35 struct memchunk *c, *d;
37 for(d=p->first; d; d = c)
42 for(d=p->first_large; d; d = c)
51 flush_pool(struct mempool *p)
55 p->free = p->last = NULL;
56 p->current = p->first;
57 while (c = p->first_large)
59 p->first_large = c->next;
65 pool_alloc(struct mempool *p, uns s)
67 if (s <= p->threshold)
69 byte *x = (byte *)(((uns) p->free + POOL_ALIGN - 1) & ~(POOL_ALIGN - 1));
76 /* Still have free chunks from previous incarnation */
82 c = xmalloc(sizeof(struct memchunk) + p->chunk_size);
88 p->last = x + p->chunk_size;
95 struct memchunk *c = xmalloc(sizeof(struct memchunk) + s);
96 c->next = p->first_large;