2 Bacula® - The Network Backup Solution
4 Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 Bacula® is a registered trademark of Kern Sibbald.
18 Definitions for the smart memory allocator
25 extern uint64_t DLL_IMP_EXP sm_max_bytes;
26 extern uint64_t DLL_IMP_EXP sm_bytes;
27 extern uint32_t DLL_IMP_EXP sm_max_buffers;
28 extern uint32_t DLL_IMP_EXP sm_buffers;
32 #define SMARTALLOC SMARTALLOC
35 extern void *sm_malloc(const char *fname, int lineno, unsigned int nbytes),
36 *sm_calloc(const char *fname, int lineno,
37 unsigned int nelem, unsigned int elsize),
38 *sm_realloc(const char *fname, int lineno, void *ptr, unsigned int size),
39 *actuallymalloc(unsigned int size),
40 *actuallycalloc(unsigned int nelem, unsigned int elsize),
41 *actuallyrealloc(void *ptr, unsigned int size);
42 extern void sm_free(const char *fname, int lineno, void *fp);
43 extern void actuallyfree(void *cp),
44 sm_dump(bool bufdump, bool in_use=false), sm_static(int mode);
45 extern void sm_new_owner(const char *fname, int lineno, char *buf);
48 #define Dsm_check(lvl) if ((lvl)<=debug_level) sm_check(__FILE__, __LINE__, true)
49 extern void sm_check(const char *fname, int lineno, bool bufdump);
50 extern int sm_check_rtn(const char *fname, int lineno, bool bufdump);
52 #define Dsm_check(lvl)
53 #define sm_check(f, l, fl)
54 #define sm_check_rtn(f, l, fl) 1
58 /* Redefine standard memory allocator calls to use our routines
61 #define free(x) sm_free(__FILE__, __LINE__, (x))
62 #define cfree(x) sm_free(__FILE__, __LINE__, (x))
63 #define malloc(x) sm_malloc(__FILE__, __LINE__, (x))
64 #define calloc(n,e) sm_calloc(__FILE__, __LINE__, (n), (e))
65 #define realloc(p,x) sm_realloc(__FILE__, __LINE__, (p), (x))
69 /* If SMARTALLOC is disabled, define its special calls to default to
70 the standard routines. */
72 #define actuallyfree(x) free(x)
73 #define actuallymalloc(x) malloc(x)
74 #define actuallycalloc(x,y) calloc(x,y)
75 #define actuallyrealloc(x,y) realloc(x,y)
78 #define sm_new_owner(a, b, c)
79 #define sm_malloc(f, l, n) malloc(n)
80 #define sm_free(f, l, n) free(n)
81 #define sm_check(f, l, fl)
82 #define sm_check_rtn(f, l, fl) 1
84 extern void *b_malloc();
85 #define malloc(x) b_malloc(__FILE__, __LINE__, (x))
92 #define New(type) new(__FILE__, __LINE__) type
94 /* We do memset(0) because it's not possible to memset a class when
95 * using subclass with virtual functions
102 void *operator new(size_t s, const char *fname, int line)
104 size_t size = s > sizeof(int) ? (unsigned int)s : sizeof(int);
105 void *p = sm_malloc(fname, line, size);
109 void *operator new[](size_t s, const char *fname, int line)
111 size_t size = s > sizeof(int) ? (unsigned int)s : sizeof(int);
112 void *p = sm_malloc(fname, line, size);
117 void operator delete(void *ptr)
121 void operator delete[](void *ptr, size_t /*i*/)
126 void operator delete(void *ptr, const char * /*fname*/, int /*line*/)
130 void operator delete[](void *ptr, size_t /*i*/,
131 const char * /*fname*/, int /*line*/)
137 void *operator new(size_t s) throw() { (void)s; return 0; }
138 void *operator new[](size_t s) throw() { (void)s; return 0; }
143 #define New(type) new type
148 void *operator new(size_t s) {
153 void *operator new[](size_t s) {
158 void operator delete(void *ptr) {
161 void operator delete[](void *ptr, size_t i) {
165 #endif /* SMARTALLOC */
167 #endif /* !SMARTALLOC_H */