2 * Sherlock Library -- Memory Pools (One-Time Allocation)
4 * (c) 1997 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);
25 p->free = p->last = NULL;
27 p->threshold = size / 3;
32 free_pool(struct mempool *p)
34 struct memchunk *c = p->chunks;
38 struct memchunk *n = c->next;
46 pool_alloc(struct mempool *p, uns s)
48 if (s <= p->threshold)
50 byte *x = (byte *)(((uns) p->free + POOL_ALIGN - 1) & ~(POOL_ALIGN - 1));
53 struct memchunk *c = xmalloc(sizeof(struct memchunk) + p->chunk_size);
57 p->last = x + p->chunk_size;
64 struct memchunk *c = xmalloc(sizeof(struct memchunk) + s);