]> jfr.im git - irc/quakenet/newserv.git/blob - core/nsmalloc.h
Remove most of the sstring code.
[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 nsinit(void);
21 void nsexit(void);
22 void *nsrealloc(unsigned int poolid, void *ptr, size_t size);
23 void nscheckfreeall(unsigned int poolid);
24 void *nscalloc(unsigned int poolid, size_t nmemb, size_t size);
25
26 #define MAXPOOL 100
27
28 struct nsminfo {
29 struct nsminfo *next;
30 struct nsminfo *prev;
31
32 size_t size;
33 char data[];
34 };
35
36 struct nsmpool {
37 unsigned long count;
38 size_t size;
39 struct nsminfo *blocks;
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 pool(ACHIEVEMENTS)
69 } endpools()
70
71 #undef pool
72 #undef beginpools
73 #undef endpools
74
75 #endif