Itasca C++ Interface
Loading...
Searching...
No Matches
basememory.h
Go to the documentation of this file.
1#include <stdlib.h>
2
3#pragma once
13#include "basedef.h"
14#include <new>
15
16namespace itasca {
17 namespace memory {
18 typedef void(*MemoryCleanupFunction)();
19
20 void initialize();
21 void shutdown();
22 BASE_EXPORT bool heapCheck(void *memptr = nullptr);
23 BASE_EXPORT unsigned long long getMemory();
24 BASE_EXPORT MemoryCleanupFunction addCleanupFunction(MemoryCleanupFunction func);
25 BASE_EXPORT void * imalloc(size_t s, const char *file, unsigned len);
26 BASE_EXPORT void * imalloc(size_t s);
27 BASE_EXPORT void ifree(void *v);
28 BASE_EXPORT void * irealloc(void *v, size_t s);
29 } // namespace memory
30} // namespace itasca
31
32#ifdef _WIN32
33#ifdef __INTEL_COMPILER
34#pragma warning(disable:3663)
35inline void *operator new(size_t s) { return itasca::memory::imalloc(s); }
36inline void *operator new[](size_t s) { return itasca::memory::imalloc(s); }
37inline void operator delete(void *v) { itasca::memory::ifree(v); }
38inline void operator delete[](void *v) { itasca::memory::ifree(v); }
39#endif
40# ifndef __PLACEMENT_NEW_INLINE
41void *operator new(size_t, void *v) { return(v); }
42void operator delete(void *, void *) { }
43# define __PLACEMENT_NEW_INLINE
44# endif
45# ifndef __PLACEMENT_VEC_NEW_INLINE
46void *operator new[](size_t, void *v) { return(v); }
47void operator delete[](void *, void *) {}
48# define __PLACEMENT_VEC_NEW_INLINE
49# endif
50
51# ifdef _DEBUG
55# define NEW(x) new(x,__FILE__,__LINE__)
56# define NEWC(x) new(#x,__FILE__,__LINE__) x
57inline void *operator new(size_t s, const char *, const char *file, unsigned line)
58{
59 return itasca::memory::imalloc(s, file, line);
60}
61inline void *operator new[](size_t s, const char *, const char *file, unsigned line)
62{
63 return itasca::memory::imalloc(s, file, line);
64}
65inline void operator delete(void *v, const char *, const char *, unsigned) { itasca::memory::ifree(v); }
66inline void operator delete[](void *v, const char *, const char *, unsigned) { itasca::memory::ifree(v); }
67# else // _DEBUG
71# define NEW(x) new
72# define NEWC(x) new x
73# endif // _DEBUG
74#endif // _WIN32
75
76
77#ifdef __LINUX
78// /// These functions are provided to replace the default new and delete functionality of the library.
79// inline void *operator new(size_t s) { return itasca::memory::imalloc(s); }
80// /// These functions are provided to replace the default new and delete functionality of the library.
81// inline void *operator new[](size_t s) { return itasca::memory::imalloc(s); }
82// /// These functions are provided to replace the default new and delete functionality of the library.
83// inline void operator delete(void *v) { itasca::memory::ifree(v); }
84// /// These functions are provided to replace the default new and delete functionality of the library.
85// inline void operator delete[](void *v) { itasca::memory::ifree(v); }
86// /*
87// # ifndef __PLACEMENT_NEW_INLINE
88// inline void *operator new(size_t,void *v) { return(v); }
89// inline void operator delete(void *,void *) { }
90// # define __PLACEMENT_NEW_INLINE
91// # endif
92// # ifndef __PLACEMENT_VEC_NEW_INLINE
93// inline void *operator new[](size_t,void *v) { return(v); }
94// inline void operator delete[](void *,void *) { }
95// # define __PLACEMENT_VEC_NEW_INLINE
96// # endif
97// */
98# ifdef _DEBUG
99// /// Using NEW or NEWC adds file and line number info to the allocated memory in debug mode.
100// /// NEWC automatically makes the comment the constructor call - for example:
101// /// NEWC(Fred(x,y)) expands to new("Fred(x,y)",__FILE__,__LINE__) Fred(x,y)
102// # define NEW(x) new(x,__FILE__,__LINE__)
103// # define NEWC(x) new(#x,__FILE__,__LINE__) x ///< \copydoc NEW
104// inline void *operator new(size_t s, const char*, const char* file, unsigned line) {
105// return itasca::memory::imalloc(s, file, line);
106// }
107// inline void *operator new[](size_t s, const char*, const char* file, unsigned line) {
108// return itasca::memory::imalloc(s, file, line);
109// }
110// inline void operator delete(void* v, const char*, const char*, unsigned) { itasca::memory::ifree(v); }
111// inline void operator delete[](void* v, const char*, const char*, unsigned) { itasca::memory::ifree(v); }
112inline void *operator new(size_t s, const char*, const char*, unsigned) { return operator new(s); }
113inline void *operator new[](size_t s, const char*, const char*, unsigned ) { return operator new(s); }
114inline void operator delete(void* v, const char*, const char*, unsigned) { return ::operator delete(v); }
115inline void operator delete[](void* v, const char*, const char*, unsigned) { return ::operator delete(v); }
116# define NEW(x) new
117# define NEWC(x) new x
118# else // _DEBUG
122# define NEW(x) new
123# define NEWC(x) new x
124# endif // _DEBUG
125#endif // ifdef linux
126
127
129// EoF
Base type definitions for the engine.
#define BASE_EXPORT
Definition basedef.h:24
namespace Itasca
Definition basememory.cpp:10