]>
Commit | Line | Data |
---|---|---|
34da4416 | 1 | /* nsmalloc: Simple pooled malloc() thing. */ |
2 | ||
271ef2d2 CP |
3 | #ifndef __NSMALLOC_H |
4 | #define __NSMALLOC_H | |
5 | ||
6 | #ifdef __NSMALLOC_C | |
7 | #define pool(x) #x | |
ed24756c | 8 | #define beginpools() char *nsmpoolnames[MAXPOOL] = |
271ef2d2 CP |
9 | #define endpools(); |
10 | #else | |
11 | #define pool(x) POOL_ ## x | |
64e3058f | 12 | #define beginpools(x) typedef enum nsmallocpools |
ed24756c | 13 | #define endpools() nsmallocpools; extern char *nsmpoolnames[MAXPOOL]; |
271ef2d2 | 14 | |
34da4416 | 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); | |
103521a1 | 20 | void nsexit(void); |
48005496 | 21 | void *nsrealloc(unsigned int poolid, void *ptr, size_t size); |
f8d5cfcf | 22 | void nscheckfreeall(unsigned int poolid); |
f358bcd6 | 23 | void *nscalloc(unsigned int poolid, size_t nmemb, size_t size); |
34da4416 | 24 | |
25 | #define MAXPOOL 100 | |
26 | ||
ed24756c CP |
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 | ||
271ef2d2 CP |
44 | #endif |
45 | ||
34da4416 | 46 | /* Pools here in the order they were created */ |
271ef2d2 CP |
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), | |
76c8da69 CP |
61 | pool(SQLITE), |
62 | pool(PQSQL), | |
024c3d57 | 63 | pool(PATRICIA), |
84ca44e7 | 64 | pool(PATRICIANICK), |
7be67351 P |
65 | pool(GLINE), |
66 | pool(TRUSTS), | |
a85729f7 | 67 | pool(SPAMSCAN2), |
96d8e39a | 68 | pool(ACHIEVEMENTS) |
271ef2d2 CP |
69 | } endpools() |
70 | ||
71 | #undef pool | |
72 | #undef beginpools | |
73 | #undef endpools | |
74 | ||
75 | #endif |