Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00054 #ifdef _MSC_VER
00055 #pragma once
00056 #endif
00057
00058 #ifndef OGDF_MEMORY_H
00059 #define OGDF_MEMORY_H
00060
00061 #if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
00062 #define WIN32_EXTRA_LEAN
00063 #define WIN32_LEAN_AND_MEAN
00064 #define NOMINMAX
00065 #ifndef _WIN32_WINNT
00066 #define _WIN32_WINNT 0x0500
00067 #endif
00068 #include <windows.h>
00069 #endif
00070
00071 #include <stdlib.h>
00072 #include <new>
00073
00074 struct MemElem { MemElem *m_next; };
00075 typedef MemElem *MemElemPtr;
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 #if !defined(OGDF_MEMORY_POOL_NTS) && !defined(OGDF_MEMORY_MALLOC_TS) && !defined(OGDF_MEMORY_POOL_TS)
00096 #define OGDF_MEMORY_POOL_TS
00097 #endif
00098
00099 #include <ogdf/internal/basic/PoolMemoryAllocator.h>
00100 #include <ogdf/internal/basic/MallocMemoryAllocator.h>
00101
00102
00103 namespace ogdf {
00104
00105 #define OGDF_MM(Alloc) \
00106 public: \
00107 void *operator new(size_t nBytes) { \
00108 if(OGDF_LIKELY(Alloc::checkSize(nBytes))) \
00109 return Alloc::allocate(nBytes); \
00110 else \
00111 return MallocMemoryAllocator::allocate(nBytes); \
00112 } \
00113 void *operator new(size_t, void *p) { return p; } \
00114 void operator delete(void *p, size_t nBytes) { \
00115 if(OGDF_LIKELY(p != 0)) { \
00116 if(OGDF_LIKELY(Alloc::checkSize(nBytes))) \
00117 Alloc::deallocate(nBytes, p); \
00118 else \
00119 MallocMemoryAllocator::deallocate(nBytes, p); \
00120 } \
00121 }
00122
00123 #define OGDF_NEW new
00124
00125 #ifdef OGDF_MEMORY_MALLOC_TS
00126 #define OGDF_ALLOCATOR ogdf::MallocMemoryAllocator
00127 #else
00128 #define OGDF_ALLOCATOR ogdf::PoolMemoryAllocator
00129 #endif
00130
00132 #define OGDF_NEW_DELETE OGDF_MM(OGDF_ALLOCATOR)
00133
00135 #define OGDF_MALLOC_NEW_DELETE OGDF_MM(MallocMemoryAllocator)
00136
00137 }
00138
00139
00140 #endif