00001
00002
00003
00004
00005
00006 #ifndef M_ALLOC_H
00007 #define M_ALLOC_H
00008
00009 #define POOL_LBUF 0
00010 #define POOL_SBUF 1
00011 #define POOL_MBUF 2
00012 #define POOL_BOOL 3
00013 #define POOL_DESC 4
00014 #define POOL_QENTRY 5
00015 #define POOL_PCACHE 6
00016 #define NUM_POOLS 7
00017
00018 #ifdef FIRANMUX
00019 #define LBUF_SIZE 16000 // Large
00020 #else
00021 #define LBUF_SIZE 8000 // Large
00022 #endif
00023 #define GBUF_SIZE 1024 // Generic
00024 #define MBUF_SIZE 400 // Medium
00025 #define PBUF_SIZE 128 // Pathname
00026 #define SBUF_SIZE 64 // Small
00027
00028 extern void pool_init(int, int);
00029 extern char *pool_alloc(int, const char *, const char *, int);
00030 extern char *pool_alloc_lbuf(const char *, const char *, int);
00031 extern void pool_free(int, char *, const char *, int);
00032 extern void pool_free_lbuf(char *, const char *, int);
00033 extern void list_bufstats(dbref);
00034 extern void list_buftrace(dbref);
00035 extern void pool_reset(void);
00036
00037 #define alloc_lbuf(s) pool_alloc_lbuf(s, __FILE__, __LINE__)
00038 #define free_lbuf(b) pool_free_lbuf((char *)(b), __FILE__, __LINE__)
00039 #define alloc_mbuf(s) pool_alloc(POOL_MBUF,s, __FILE__, __LINE__)
00040 #define free_mbuf(b) pool_free(POOL_MBUF,(char *)(b), __FILE__, __LINE__)
00041 #define alloc_sbuf(s) pool_alloc(POOL_SBUF,s, __FILE__, __LINE__)
00042 #define free_sbuf(b) pool_free(POOL_SBUF,(char *)(b), __FILE__, __LINE__)
00043 #define alloc_bool(s) (struct boolexp *)pool_alloc(POOL_BOOL,s, __FILE__, __LINE__)
00044 #define free_bool(b) pool_free(POOL_BOOL,(char *)(b), __FILE__, __LINE__)
00045 #define alloc_qentry(s) (BQUE *)pool_alloc(POOL_QENTRY,s, __FILE__, __LINE__)
00046 #define free_qentry(b) pool_free(POOL_QENTRY,(char *)(b), __FILE__, __LINE__)
00047 #define alloc_pcache(s) (PCACHE *)pool_alloc(POOL_PCACHE,s, __FILE__, __LINE__)
00048 #define free_pcache(b) pool_free(POOL_PCACHE,(char *)(b), __FILE__, __LINE__)
00049
00050 #define safe_copy_chr(src, buff, bufp, nSizeOfBuffer) \
00051 { \
00052 if ((*bufp - buff) < nSizeOfBuffer) \
00053 { \
00054 **bufp = src; \
00055 (*bufp)++; \
00056 } \
00057 }
00058
00059 #define safe_str(s,b,p) safe_copy_str_lbuf(s,b,p)
00060 #define safe_chr(c,b,p) safe_copy_chr((unsigned char)(c),b,p,(LBUF_SIZE-1))
00061 #define safe_bool(c,b,p) safe_chr(((c) ? '1' : '0'),b,p)
00062 #define safe_sb_str(s,b,p) safe_copy_str(s,b,p,(SBUF_SIZE-1))
00063 #define safe_sb_chr(c,b,p) safe_copy_chr(c,b,p,(SBUF_SIZE-1))
00064 #define safe_mb_str(s,b,p) safe_copy_str(s,b,p,(MBUF_SIZE-1))
00065 #define safe_mb_chr(c,b,p) safe_copy_chr(c,b,p,(MBUF_SIZE-1))
00066
00067 #endif // M_ALLOC_H