]>
jfr.im git - irc/quakenet/newserv.git/blob - channel/channelalloc.c
6 #include "../core/nsmalloc.h"
11 chanuserhash
*freehash
;
13 void initchannelalloc() {
18 /* channel records don't have next pointers.
19 * Overload the index pointer for chaining free channels */
25 if (freechans
==NULL
) {
26 freechans
=(channel
*)nsmalloc(POOL_CHANNEL
,ALLOCUNIT
*sizeof(channel
));
27 for (i
=0;i
<(ALLOCUNIT
-1);i
++) {
28 freechans
[i
].index
=(struct chanindex
*)&(freechans
[i
+1]);
30 freechans
[ALLOCUNIT
-1].index
=NULL
;
34 freechans
=(channel
*)cp
->index
;
39 void freechan(channel
*cp
) {
40 cp
->index
=(struct chanindex
*)freechans
;
47 * Since these things don't naturally have a "next" pointer
48 * we abuse the "content" pointer to build our list of free
51 * Hence some somewhat bizarre casts...
54 chanuserhash
*newchanuserhash(int hashsize
) {
59 freehash
=(chanuserhash
*)nsmalloc(POOL_CHANNEL
,ALLOCUNIT
*sizeof(chanuserhash
));
60 for (i
=0;i
<(ALLOCUNIT
-1);i
++) {
61 freehash
[i
].content
=(unsigned long *)&(freehash
[i
+1]);
63 freehash
[ALLOCUNIT
-1].content
=NULL
;
67 freehash
=(chanuserhash
*)cuhp
->content
;
69 /* Don't use nsmalloc() here since we will free this in freechanuserhash() */
70 cuhp
->content
=(unsigned long *)malloc(hashsize
*sizeof(unsigned long));
71 for (i
=0;i
<hashsize
;i
++) {
72 cuhp
->content
[i
]=nouser
;
75 cuhp
->hashsize
=hashsize
;
81 void freechanuserhash(chanuserhash
*cuhp
) {
83 cuhp
->content
=(unsigned long *)freehash
;