]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/mem_pool.h
Update copyright
[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    Bacula® - The Network Backup Solution
10
11    Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
12
13    The main author of Bacula is Kern Sibbald, with contributions from
14    many others, a complete list can be found in the file AUTHORS.
15    This program is Free Software; you can redistribute it and/or
16    modify it under the terms of version two of the GNU General Public
17    License as published by the Free Software Foundation plus additions
18    that are listed in the file LICENSE.
19
20    This program is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23    General Public License for more details.
24
25    You should have received a copy of the GNU General Public License
26    along with this program; if not, write to the Free Software
27    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28    02110-1301, USA.
29
30    Bacula® is a registered trademark of John Walker.
31    The licensor of Bacula is the Free Software Foundation Europe
32    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
33    Switzerland, email:ftf@fsfeurope.org.
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    int size() const { return sizeof_pool_memory(mem); }
95    char *check_size(int32_t size) {
96       mem = check_pool_memory_size(mem, size);
97       return mem;
98    }
99    int32_t max_size();
100    void realloc_pm(int32_t size);
101    int strcpy(const char *str);
102    int strcat(const char *str);
103 };
104
105 int pm_strcat (POOLMEM **pm, const char *str);
106 int pm_strcat (POOLMEM *&pm, const char *str);
107 int pm_strcat (POOL_MEM &pm, const char *str);
108 int pm_strcat (POOLMEM *&pm, POOL_MEM &str);
109 int pm_strcpy (POOLMEM **pm, const char *str);
110 int pm_strcpy (POOLMEM *&pm, const char *str);
111 int pm_strcpy (POOL_MEM &pm, const char *str);
112 int pm_strcpy (POOLMEM *&pm, POOL_MEM &str);
113
114
115 #endif