]> jfr.im git - irc/quakenet/newserv.git/blob - core/nsmalloc.h
Merge pull request #132 from retropc/lua_country
[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 #include <stdint.h>
17
18 void *nsmalloc(unsigned int poolid, size_t size);
19 void nsfree(unsigned int poolid, void *ptr);
20 void nsfreeall(unsigned int poolid);
21 void nsinit(void);
22 void nsexit(void);
23 void *nsrealloc(unsigned int poolid, void *ptr, size_t size);
24 void nscheckfreeall(unsigned int poolid);
25 void *nscalloc(unsigned int poolid, size_t nmemb, size_t size);
26
27 #define MAXPOOL 100
28 #define REDZONE_MAGIC 0x243653E957851F68ULL
29 struct nsminfo {
30 struct nsminfo *next;
31 struct nsminfo *prev;
32
33 size_t size;
34 uint64_t redzone;
35 char data[];
36 };
37
38 struct nsmpool {
39 unsigned long count;
40 size_t size;
41 struct nsminfo *blocks;
42 };
43
44 extern struct nsmpool nsmpools[MAXPOOL];
45
46 #endif
47
48 /* Pools here in the order they were created */
49
50 beginpools() {
51 pool(AUTHEXT),
52 pool(CHANINDEX),
53 pool(BANS),
54 pool(CHANNEL),
55 pool(NICK),
56 pool(CHANSERVDB),
57 pool(SSTRING),
58 pool(AUTHTRACKER),
59 pool(PROXYSCAN),
60 pool(LUA),
61 pool(TROJANSCAN),
62 pool(NTERFACER),
63 pool(SQLITE),
64 pool(PQSQL),
65 pool(PATRICIA),
66 pool(PATRICIANICK),
67 pool(GLINE),
68 pool(TRUSTS),
69 pool(SPAMSCAN2),
70 pool(ACHIEVEMENTS),
71 pool(CHANSTATS),
72 pool(SCHEDULE)
73 } endpools()
74
75 #undef pool
76 #undef beginpools
77 #undef endpools
78
79 #endif