2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
22 Definitions for the smart memory allocator
29 extern uint64_t DLL_IMP_EXP sm_max_bytes;
30 extern uint64_t DLL_IMP_EXP sm_bytes;
31 extern uint32_t DLL_IMP_EXP sm_max_buffers;
32 extern uint32_t DLL_IMP_EXP sm_buffers;
36 #define SMARTALLOC SMARTALLOC
39 extern void *sm_malloc(const char *fname, int lineno, unsigned int nbytes),
40 *sm_calloc(const char *fname, int lineno,
41 unsigned int nelem, unsigned int elsize),
42 *sm_realloc(const char *fname, int lineno, void *ptr, unsigned int size),
43 *actuallymalloc(unsigned int size),
44 *actuallycalloc(unsigned int nelem, unsigned int elsize),
45 *actuallyrealloc(void *ptr, unsigned int size);
46 extern void sm_free(const char *fname, int lineno, void *fp);
47 extern void actuallyfree(void *cp),
48 sm_dump(bool bufdump, bool in_use=false), sm_static(int mode);
49 extern void sm_new_owner(const char *fname, int lineno, char *buf);
52 #define Dsm_check(lvl) if ((lvl)<=debug_level) sm_check(__FILE__, __LINE__, true)
53 extern void sm_check(const char *fname, int lineno, bool bufdump);
54 extern int sm_check_rtn(const char *fname, int lineno, bool bufdump);
56 #define Dsm_check(lvl)
57 #define sm_check(f, l, fl)
58 #define sm_check_rtn(f, l, fl) 1
62 /* Redefine standard memory allocator calls to use our routines
65 #define free(x) sm_free(__FILE__, __LINE__, (x))
66 #define cfree(x) sm_free(__FILE__, __LINE__, (x))
67 #define malloc(x) sm_malloc(__FILE__, __LINE__, (x))
68 #define calloc(n,e) sm_calloc(__FILE__, __LINE__, (n), (e))
69 #define realloc(p,x) sm_realloc(__FILE__, __LINE__, (p), (x))
73 /* If SMARTALLOC is disabled, define its special calls to default to
74 the standard routines. */
76 #define actuallyfree(x) free(x)
77 #define actuallymalloc(x) malloc(x)
78 #define actuallycalloc(x,y) calloc(x,y)
79 #define actuallyrealloc(x,y) realloc(x,y)
82 #define sm_new_owner(a, b, c)
83 #define sm_malloc(f, l, n) malloc(n)
84 #define sm_free(f, l, n) free(n)
85 #define sm_check(f, l, fl)
86 #define sm_check_rtn(f, l, fl) 1
88 extern void *b_malloc();
89 #define malloc(x) b_malloc(__FILE__, __LINE__, (x))
96 #define New(type) new(__FILE__, __LINE__) type
98 /* We do memset(0) because it's not possible to memset a class when
99 * using subclass with virtual functions
106 void *operator new(size_t s, const char *fname, int line)
108 size_t size = s > sizeof(int) ? (unsigned int)s : sizeof(int);
109 void *p = sm_malloc(fname, line, size);
113 void *operator new[](size_t s, const char *fname, int line)
115 size_t size = s > sizeof(int) ? (unsigned int)s : sizeof(int);
116 void *p = sm_malloc(fname, line, size);
121 void operator delete(void *ptr)
125 void operator delete[](void *ptr, size_t /*i*/)
130 void operator delete(void *ptr, const char * /*fname*/, int /*line*/)
134 void operator delete[](void *ptr, size_t /*i*/,
135 const char * /*fname*/, int /*line*/)
141 void *operator new(size_t s) throw() { (void)s; return 0; }
142 void *operator new[](size_t s) throw() { (void)s; return 0; }
147 #define New(type) new type
152 void *operator new(size_t s) {
157 void *operator new[](size_t s) {
162 void operator delete(void *ptr) {
165 void operator delete[](void *ptr, size_t i) {
169 #endif /* SMARTALLOC */
171 #endif /* !SMARTALLOC_H */