]>
jfr.im git - irc/quakenet/newserv.git/blob - chanstats/chanstatsalloc.c
1 /* Allocators for chanstats */
9 static void *malloclist
;
10 static chanstats
*freecs
;
12 void *cstsmalloc(size_t size
) {
15 /* Get the memory we want, with an extra four bytes for our pointer */
16 mem
=(void **)malloc(size
+sizeof(void *));
18 /* Set the first word to point at the last chunk we got */
21 /* Now set the "last chunk" pointer to the address of this one */
22 malloclist
=(void *)mem
;
24 /* Return the rest of the memory to the caller */
25 return (void *)(mem
+1);
40 void initchanstatsalloc() {
45 chanstats
*getchanstats() {
50 freecs
=(chanstats
*)cstsmalloc(ALLOCUNIT
*sizeof(chanstats
));
51 for(i
=0;i
<(ALLOCUNIT
-1);i
++) {
52 freecs
[i
].index
=(chanindex
*)&(freecs
[i
+1]);
54 freecs
[ALLOCUNIT
-1].index
=NULL
;
58 freecs
=(chanstats
*)csp
->index
;
63 void freechanstats(chanstats
*csp
) {
64 csp
->index
=(chanindex
*)freecs
;