X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/c86edd1d9e5994aea33cfad3164e4827e591e7e6..5f5fc0447463454812f1de465387cf1ca99eaf69:/nick/nickalloc.c diff --git a/nick/nickalloc.c b/nick/nickalloc.c index d2a2889d..64a62b9d 100644 --- a/nick/nickalloc.c +++ b/nick/nickalloc.c @@ -1,24 +1,14 @@ -/* nick/host/realname allocator */ +/* nick/host/realname/authname allocator */ #include "nick.h" +#include "../core/nsmalloc.h" + #include #include -#define ALLOCUNIT 100 - /* Hosts and realname structures are the same size */ /* This assumption is checked in initnickalloc(); */ -nick *freenicks; -host *freehosts; - -void initnickalloc() { - freenicks=NULL; - freehosts=NULL; - - assert(sizeof(host)==sizeof(realname)); -} - realname *newrealname() { return (realname *)newhost(); } @@ -28,47 +18,18 @@ void freerealname(realname *rn) { } nick *newnick() { - nick *np; - int i; - - if (freenicks==NULL) { - freenicks=(nick *)malloc(ALLOCUNIT*sizeof(nick)); - for (i=0;i<(ALLOCUNIT-1);i++) { - freenicks[i].next=&(freenicks[i+1]); - } - freenicks[ALLOCUNIT-1].next=NULL; - } - - np=freenicks; - freenicks=np->next; - - return np; + return nsmalloc(POOL_NICK, sizeof(nick)); } -void freenick (nick *np) { - np->next=freenicks; - freenicks=np; +void freenick(nick *np) { + nsfree(POOL_NICK, np); } host *newhost() { - host *nh; - int i; - - if (freehosts==NULL) { - freehosts=(host *)malloc(ALLOCUNIT*sizeof(host)); - for (i=0;i<(ALLOCUNIT-1);i++) { - freehosts[i].next=&(freehosts[i+1]); - } - freehosts[ALLOCUNIT-1].next=NULL; - } - - nh=freehosts; - freehosts=nh->next; - - return nh; + return nsmalloc(POOL_NICK, sizeof(host)); } -void freehost (host *hp) { - hp->next=freehosts; - freehosts=hp; +void freehost(host *hp) { + nsfree(POOL_NICK, hp); } +