]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/mem_pool.h
15Jan06
[bacula/bacula] / bacula / src / lib / mem_pool.h
1 /*
2  * Memory Pool prototypes
3  *
4  *  Kern Sibbald, MM
5  *
6  *   Version $Id$
7  */
8 /*
9    Copyright (C) 2000-2006 Kern Sibbald
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License
13    version 2 as amended with additional clauses defined in the
14    file LICENSE in the main source directory.
15
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
19    the file LICENSE for additional details.
20
21  */
22
23 #ifndef __MEM_POOL_H_
24 #define __MEM_POOL_H_
25
26
27 #ifdef SMARTALLOC
28
29 #define get_pool_memory(pool) sm_get_pool_memory(__FILE__, __LINE__, pool)
30 extern POOLMEM *sm_get_pool_memory(const char *file, int line, int pool);
31
32 #define get_memory(size) sm_get_memory(__FILE__, __LINE__, size)
33 extern POOLMEM *sm_get_memory(const char *fname, int line, int32_t size);
34
35 #define sizeof_pool_memory(buf) sm_sizeof_pool_memory(__FILE__, __LINE__, buf)
36 extern int32_t sm_sizeof_pool_memory(const char *fname, int line, POOLMEM *buf);
37
38 #define realloc_pool_memory(buf,size) sm_realloc_pool_memory(__FILE__, __LINE__, buf, size)
39 extern POOLMEM  *sm_realloc_pool_memory(const char *fname, int line, POOLMEM *buf, int32_t size);
40
41 #define check_pool_memory_size(buf,size) sm_check_pool_memory_size(__FILE__, __LINE__, buf, size)
42 extern POOLMEM  *sm_check_pool_memory_size(const char *fname, int line, POOLMEM *buf, int32_t size);
43
44 #define free_pool_memory(x) sm_free_pool_memory(__FILE__, __LINE__, x)
45 #define free_memory(x) sm_free_pool_memory(__FILE__, __LINE__, x)
46 extern void sm_free_pool_memory(const char *fname, int line, POOLMEM *buf);
47
48
49 #else
50
51 extern POOLMEM *get_pool_memory(int pool);
52 extern POOLMEM *get_memory(int32_t size);
53 extern int32_t sizeof_pool_memory(POOLMEM *buf);
54 extern POOLMEM  *realloc_pool_memory(POOLMEM *buf, int32_t size);
55 extern POOLMEM  *check_pool_memory_size(POOLMEM *buf, int32_t size);
56 #define free_memory(x) free_pool_memory(x)
57 extern void   free_pool_memory(POOLMEM *buf);
58
59 #endif
60
61 extern void garbage_collect_memory_pool();
62 extern void  close_memory_pool();
63 extern void  print_memory_pool_stats();
64
65
66
67 #define PM_NOPOOL  0                  /* nonpooled memory */
68 #define PM_NAME    1                  /* Bacula name */
69 #define PM_FNAME   2                  /* file name buffer */
70 #define PM_MESSAGE 3                  /* daemon message */
71 #define PM_EMSG    4                  /* error message */
72 #define PM_MAX     PM_EMSG            /* Number of types */
73
74 class POOL_MEM {
75    char *mem;
76 public:
77    POOL_MEM() { mem = get_pool_memory(PM_NAME); *mem = 0; }
78    POOL_MEM(int pool) { mem = get_pool_memory(pool); *mem = 0; }
79    ~POOL_MEM() { free_pool_memory(mem); mem = NULL; }
80    char *c_str() const { return mem; }
81    int size() const { return sizeof_pool_memory(mem); }
82    char *check_size(int32_t size) {
83       mem = check_pool_memory_size(mem, size);
84       return mem;
85    }
86    int32_t max_size();
87    void realloc_pm(int32_t size);
88    int strcpy(const char *str);
89    int strcat(const char *str);
90 };
91
92 int pm_strcat (POOLMEM **pm, const char *str);
93 int pm_strcat (POOLMEM *&pm, const char *str);
94 int pm_strcat (POOL_MEM &pm, const char *str);
95 int pm_strcat (POOLMEM *&pm, POOL_MEM &str);
96 int pm_strcpy (POOLMEM **pm, const char *str);
97 int pm_strcpy (POOLMEM *&pm, const char *str);
98 int pm_strcpy (POOL_MEM &pm, const char *str);
99 int pm_strcpy (POOLMEM *&pm, POOL_MEM &str);
100
101
102 #endif