]> 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
24 #define MAXPOOL 100
25
26 struct nsminfo {
27 struct nsminfo *next;
28 struct nsminfo *prev;
29
30 size_t size;
31 char data[];
32 };
33
34 struct nsmpool {
35 struct nsminfo first;
36
37 unsigned long count;
38 size_t size;
39 };
40
41 extern struct nsmpool nsmpools[MAXPOOL];
42
43 #endif
44
45 /* Pools here in the order they were created */
46
47 beginpools() {
48 pool(AUTHEXT),
49 pool(CHANINDEX),
50 pool(BANS),
51 pool(CHANNEL),
52 pool(NICK),
53 pool(CHANSERVDB),
54 pool(SSTRING),
55 pool(AUTHTRACKER),
56 pool(PROXYSCAN),
57 pool(LUA),
58 pool(TROJANSCAN),
59 pool(NTERFACER),
60 pool(SQLITE),
61 pool(PQSQL),
62 pool(PATRICIA),
63 } endpools()
64
65 #undef pool
66 #undef beginpools
67 #undef endpools
68
69 #endif