2 * Author: Humberto Naves (hsnaves@gmail.com)
16 struct _link
*allocated
;
17 struct _link
*nextfree
;
25 fixedpool
fixedpool_create (size_t size
, size_t grownum
, int setzero
)
27 fixedpool p
= (fixedpool
) xmalloc (sizeof (struct _fixedpool
));
29 if (size
< sizeof (struct _link
)) size
= sizeof (struct _link
);
30 if (grownum
< 2) grownum
= 2;
41 void fixedpool_destroy (fixedpool p
, pooltraversefn destroyfn
, void *arg
)
43 struct _link
*ptr
, *nptr
;
47 for (ptr
= p
->allocated
; ptr
; ptr
= nptr
) {
53 while (count
<= ptr
->size
) {
69 void fixedpool_grow (fixedpool p
, void *ptr
, size_t ptrsize
)
75 if (ptrsize
< 2 * p
->size
) {
81 l
->next
= p
->allocated
;
90 while (count
<= ptrsize
) {
91 l
= (struct _link
*) c
;
92 l
->next
= p
->nextfree
;
99 void *fixedpool_alloc (fixedpool p
)
106 size
= p
->grownum
* p
->size
;
107 ptr
= xmalloc (size
);
108 fixedpool_grow (p
, ptr
, size
);
111 p
->nextfree
= l
->next
;
113 memset (l
, 0, p
->size
);
117 void fixedpool_free (fixedpool p
, void *ptr
)
119 struct _link
*l
= ptr
;
120 l
->next
= p
->nextfree
;