13 struct _link
*allocated
;
14 struct _link
*nextfree
;
22 fixedpool
fixedpool_create (size_t size
, size_t grownum
, int setzero
)
24 fixedpool p
= (fixedpool
) xmalloc (sizeof (struct _fixedpool
));
26 if (size
< sizeof (struct _link
)) size
= sizeof (struct _link
);
27 if (grownum
< 2) grownum
= 2;
38 void fixedpool_destroy (fixedpool p
, pooltraversefn destroyfn
, void *arg
)
40 struct _link
*ptr
, *nptr
;
44 for (ptr
= p
->allocated
; ptr
; ptr
= nptr
) {
50 while (count
<= ptr
->size
) {
66 void fixedpool_grow (fixedpool p
, void *ptr
, size_t ptrsize
)
72 if (ptrsize
< 2 * p
->size
) {
78 l
->next
= p
->allocated
;
87 while (count
<= ptrsize
) {
88 l
= (struct _link
*) c
;
89 l
->next
= p
->nextfree
;
96 void *fixedpool_alloc (fixedpool p
)
103 size
= p
->grownum
* p
->size
;
104 ptr
= xmalloc (size
);
105 fixedpool_grow (p
, ptr
, size
);
108 p
->nextfree
= l
->next
;
110 memset (l
, 0, p
->size
);
114 void fixedpool_free (fixedpool p
, void *ptr
)
116 struct _link
*l
= ptr
;
117 l
->next
= p
->nextfree
;