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