]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/mem_pool.h
bd39d7500967c2b1e43ebbea914a10486ada2a1a
[bacula/bacula] / bacula / src / lib / mem_pool.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  * Memory Pool prototypes
30  *
31  *  Kern Sibbald, MM
32  *
33  *   Version $Id$
34  */
35
36 #ifndef __MEM_POOL_H_
37 #define __MEM_POOL_H_
38
39
40 #ifdef SMARTALLOC
41
42 #define get_pool_memory(pool) sm_get_pool_memory(__FILE__, __LINE__, pool)
43 extern POOLMEM *sm_get_pool_memory(const char *file, int line, int pool);
44
45 #define get_memory(size) sm_get_memory(__FILE__, __LINE__, size)
46 extern POOLMEM *sm_get_memory(const char *fname, int line, int32_t size);
47
48 #define sizeof_pool_memory(buf) sm_sizeof_pool_memory(__FILE__, __LINE__, buf)
49 extern int32_t sm_sizeof_pool_memory(const char *fname, int line, POOLMEM *buf);
50
51 #define realloc_pool_memory(buf,size) sm_realloc_pool_memory(__FILE__, __LINE__, buf, size)
52 extern POOLMEM  *sm_realloc_pool_memory(const char *fname, int line, POOLMEM *buf, int32_t size);
53
54 #define check_pool_memory_size(buf,size) sm_check_pool_memory_size(__FILE__, __LINE__, buf, size)
55 extern POOLMEM  *sm_check_pool_memory_size(const char *fname, int line, POOLMEM *buf, int32_t size);
56
57 #define free_pool_memory(x) sm_free_pool_memory(__FILE__, __LINE__, x)
58 #define free_memory(x) sm_free_pool_memory(__FILE__, __LINE__, x)
59 extern void sm_free_pool_memory(const char *fname, int line, POOLMEM *buf);
60
61
62 #else
63
64 extern POOLMEM *get_pool_memory(int pool);
65 extern POOLMEM *get_memory(int32_t size);
66 extern int32_t sizeof_pool_memory(POOLMEM *buf);
67 extern POOLMEM  *realloc_pool_memory(POOLMEM *buf, int32_t size);
68 extern POOLMEM  *check_pool_memory_size(POOLMEM *buf, int32_t size);
69 #define free_memory(x) free_pool_memory(x)
70 extern void   free_pool_memory(POOLMEM *buf);
71
72 #endif
73
74 extern void garbage_collect_memory_pool();
75 extern void  close_memory_pool();
76 extern void  print_memory_pool_stats();
77
78
79
80 #define PM_NOPOOL  0                  /* nonpooled memory */
81 #define PM_NAME    1                  /* Bacula name */
82 #define PM_FNAME   2                  /* file name buffer */
83 #define PM_MESSAGE 3                  /* daemon message */
84 #define PM_EMSG    4                  /* error message */
85 #define PM_MAX     PM_EMSG            /* Number of types */
86
87 class POOL_MEM {
88    char *mem;
89 public:
90    POOL_MEM() { mem = get_pool_memory(PM_NAME); *mem = 0; }
91    POOL_MEM(int pool) { mem = get_pool_memory(pool); *mem = 0; }
92    ~POOL_MEM() { free_pool_memory(mem); mem = NULL; }
93    char *c_str() const { return mem; }
94    POOLMEM *&addr() { return mem; }
95    int size() const { return sizeof_pool_memory(mem); }
96    char *check_size(int32_t size) {
97       mem = check_pool_memory_size(mem, size);
98       return mem;
99    }
100    int32_t max_size();
101    void realloc_pm(int32_t size);
102    int strcpy(const char *str);
103    int strcat(const char *str);
104 };
105
106 int pm_strcat(POOLMEM **pm, const char *str);
107 int pm_strcat(POOLMEM *&pm, const char *str);
108 int pm_strcat(POOL_MEM &pm, const char *str);
109 int pm_strcat(POOLMEM *&pm, POOL_MEM &str);
110
111 int pm_strcpy(POOLMEM **pm, const char *str);
112 int pm_strcpy(POOLMEM *&pm, const char *str);
113 int pm_strcpy(POOL_MEM &pm, const char *str);
114 int pm_strcpy(POOLMEM *&pm, POOL_MEM &str);
115
116 int pm_memcpy(POOLMEM **pm, const char *data, int32_t n);
117 int pm_memcpy(POOLMEM *&pm, const char *data, int32_t n);
118 int pm_memcpy(POOL_MEM &pm, const char *data, int32_t n);
119 int pm_memcpy(POOLMEM *&pm, POOL_MEM &data, int32_t n);
120
121 #endif