]> jfr.im git - irc/quakenet/newserv.git/blame_incremental - core/nsmalloc.h
gline playground
[irc/quakenet/newserv.git] / core / nsmalloc.h
... / ...
CommitLineData
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
17void *nsmalloc(unsigned int poolid, size_t size);
18void nsfree(unsigned int poolid, void *ptr);
19void nsfreeall(unsigned int poolid);
20void nsexit(void);
21void *nsrealloc(unsigned int poolid, void *ptr, size_t size);
22void nscheckfreeall(unsigned int poolid);
23void *nscalloc(unsigned int poolid, size_t nmemb, size_t size);
24
25#define MAXPOOL 100
26
27struct nsminfo {
28 struct nsminfo *next;
29 struct nsminfo *prev;
30
31 size_t size;
32 char data[];
33};
34
35struct nsmpool {
36 struct nsminfo first;
37
38 unsigned long count;
39 size_t size;
40};
41
42extern struct nsmpool nsmpools[MAXPOOL];
43
44#endif
45
46/* Pools here in the order they were created */
47
48beginpools() {
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