]> jfr.im git - irc/quakenet/newserv.git/blob - core/nsmalloc.h
Merge.
[irc/quakenet/newserv.git] / core / nsmalloc.h
1 /* nsmalloc: Simple pooled malloc() thing. */
2
3 #ifndef __NSMALLOC_H
4 #define __NSMALLOC_H
5
6 #ifdef __NSMALLOC_C
7 #define pool(x) #x
8 #define beginpools() char *nsmpoolnames[MAXPOOL] =
9 #define endpools();
10 #else
11 #define pool(x) POOL_ ## x
12 #define beginpools(x) typedef enum nsmallocpools
13 #define endpools() nsmallocpools; extern char *nsmpoolnames[MAXPOOL];
14
15 #include <stdlib.h>
16
17 void *nsmalloc(unsigned int poolid, size_t size);
18 void nsfree(unsigned int poolid, void *ptr);
19 void nsfreeall(unsigned int poolid);
20 void nsexit(void);
21 void *nsrealloc(unsigned int poolid, void *ptr, size_t size);
22 void nscheckfreeall(unsigned int poolid);
23 void *nscalloc(unsigned int poolid, size_t nmemb, size_t size);
24
25 #define MAXPOOL 100
26
27 struct nsminfo {
28 struct nsminfo *next;
29 struct nsminfo *prev;
30
31 size_t size;
32 char data[];
33 };
34
35 struct nsmpool {
36 struct nsminfo first;
37
38 unsigned long count;
39 size_t size;
40 };
41
42 extern struct nsmpool nsmpools[MAXPOOL];
43
44 #endif
45
46 /* Pools here in the order they were created */
47
48 beginpools() {
49 pool(AUTHEXT),
50 pool(CHANINDEX),
51 pool(BANS),
52 pool(CHANNEL),
53 pool(NICK),
54 pool(CHANSERVDB),
55 pool(SSTRING),
56 pool(AUTHTRACKER),
57 pool(PROXYSCAN),
58 pool(LUA),
59 pool(TROJANSCAN),
60 pool(NTERFACER),
61 pool(SQLITE),
62 pool(PQSQL),
63 pool(PATRICIA),
64 pool(PATRICIANICK),
65 pool(GLINE),
66 pool(TRUSTS),
67 pool(SPAMSCAN2),
68 } endpools()
69
70 #undef pool
71 #undef beginpools
72 #undef endpools
73
74 #endif