Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

MallocMemoryAllocator.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/Logger.h>
36 #include <ogdf/basic/exceptions.h>
37 
38 namespace ogdf {
39 
42 {
43  struct MemElem { MemElem *m_next; };
44  using MemElemPtr = MemElem*;
45 
46 public:
47 
50 
51  static void cleanup() { }
52 
54  static inline void *allocate(size_t nBytes, const char *, int) {
55  return allocate(nBytes);
56  }
57 
59  static inline void *allocate(size_t nBytes)
60  {
61  void *p = malloc(nBytes);
63  return p;
64  }
65 
66 
69  static inline void deallocate(size_t, void *p) {
70  free(p);
71  }
72 
74 
77  static void deallocateList(size_t /* nBytes */, void *pHead, void *pTail)
78  {
79  MemElemPtr q, pStop = MemElemPtr(pTail)->m_next;
80  while (pHead != pStop) {
81  q = MemElemPtr(pHead)->m_next;
82  free(pHead);
83  pHead = q;
84  }
85  }
86 
87  static void flushPool() { }
88  static void flushPool(uint16_t /* nBytes */) { }
89 
91  static constexpr bool checkSize(size_t) {
92  return true;
93  }
94 
96  static constexpr size_t memoryAllocatedInBlocks() {
97  return 0;
98  }
99 
101  static constexpr size_t memoryInFreelist() {
102  return 0;
103  }
104 
106  static constexpr size_t memoryInGlobalFreeList() {
107  return 0;
108  }
109 
111  static constexpr size_t memoryInThreadFreeList() {
112  return 0;
113  }
114 };
115 
116 }
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
static void deallocateList(size_t, void *pHead, void *pTail)
Deallocate a complete list starting at pHead and ending at pTail.
#define OGDF_THROW(CLASS)
Replacement for throw.
Definition: exceptions.h:65
#define OGDF_UNLIKELY(x)
Specify the unlikely branch in a condition.
Definition: config.h:148
static void * allocate(size_t nBytes, const char *, int)
Allocates memory of size nBytes.
static constexpr size_t memoryAllocatedInBlocks()
Always returns 0, since no blocks are allocated.
Contains logging functionality.
static constexpr size_t memoryInThreadFreeList()
Always returns 0, since no blocks are allocated.
Definition of exception classes.
Exception thrown when not enough memory is available to execute an algorithm.
Definition: exceptions.h:213
static void flushPool(uint16_t)
static void deallocate(size_t, void *p)
Deallocates memory at address p. We do not keep track of the size of the deallocated object...
The namespace for all OGDF objects.
static constexpr size_t memoryInGlobalFreeList()
Always returns 0, since no blocks are allocated.
Implements a simple memory manager using malloc() and free().
static constexpr bool checkSize(size_t)
Always returns true since we simply trust malloc().
static void * allocate(size_t nBytes)
Allocates memory of size nBytes.
static constexpr size_t memoryInFreelist()
Always returns 0, since no blocks are allocated.