2 * Sherlock Library -- Memory Pools (One-Time Allocation)
4 * (c) 1997--2001 Martin Mares <mj@ucw.cz>
13 struct memchunk *next;
20 struct mempool *p = xmalloc(sizeof(struct mempool));
22 size -= sizeof(struct memchunk);
23 p->free = p->last = NULL;
24 p->first = p->current = p->first_large = NULL;
27 p->threshold = size / 3;
32 mp_delete(struct mempool *p)
34 struct memchunk *c, *d;
36 for(d=p->first; d; d = c)
41 for(d=p->first_large; d; d = c)
50 mp_flush(struct mempool *p)
54 p->free = p->last = NULL;
55 p->current = p->first;
56 while (c = p->first_large)
58 p->first_large = c->next;
64 mp_alloc(struct mempool *p, uns s)
66 if (s <= p->threshold)
68 byte *x = (byte *)(((uns) p->free + POOL_ALIGN - 1) & ~(POOL_ALIGN - 1));
75 /* Still have free chunks from previous incarnation */
81 c = xmalloc(sizeof(struct memchunk) + p->chunk_size);
87 p->last = x + p->chunk_size;
94 struct memchunk *c = xmalloc(sizeof(struct memchunk) + s);
95 c->next = p->first_large;