]> jfr.im git - irc/quakenet/newserv.git/blame_incremental - core/nsmalloc.h
initial commit - patricia nick index
[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);
23
24#define MAXPOOL 100
25
26struct nsminfo {
27 struct nsminfo *next;
28 struct nsminfo *prev;
29
30 size_t size;
31 char data[];
32};
33
34struct nsmpool {
35 struct nsminfo first;
36
37 unsigned long count;
38 size_t size;
39};
40
41extern struct nsmpool nsmpools[MAXPOOL];
42
43#endif
44
45/* Pools here in the order they were created */
46
47beginpools() {
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 pool(PATRICIANICK),
64} endpools()
65
66#undef pool
67#undef beginpools
68#undef endpools
69
70#endif