Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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  struct MemElem {
44  };
45 
46  using MemElemPtr = MemElem*;
47 
48 public:
50 
52 
53  static void cleanup() { }
54 
56  static inline void* allocate(size_t nBytes, const char*, int) { return allocate(nBytes); }
57 
59  static inline void* allocate(size_t nBytes) {
60  void* p = malloc(nBytes);
61  if (OGDF_UNLIKELY(p == nullptr)) {
63  }
64  return p;
65  }
66 
69  static inline void deallocate(size_t, void* p) { free(p); }
70 
72 
75  static void deallocateList(size_t /* nBytes */, void* pHead, void* pTail) {
76  MemElemPtr q, pStop = MemElemPtr(pTail)->m_next;
77  while (pHead != pStop) {
78  q = MemElemPtr(pHead)->m_next;
79  free(pHead);
80  pHead = q;
81  }
82  }
83 
84  static void flushPool() { }
85 
86  static void flushPool(uint16_t /* nBytes */) { }
87 
89  static constexpr bool checkSize(size_t) { return true; }
90 
92  static constexpr size_t memoryAllocatedInBlocks() { return 0; }
93 
95  static constexpr size_t memoryInFreelist() { return 0; }
96 
98  static constexpr size_t memoryInGlobalFreeList() { return 0; }
99 
101  static constexpr size_t memoryInThreadFreeList() { return 0; }
102 };
103 
104 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::MallocMemoryAllocator::memoryInGlobalFreeList
static constexpr size_t memoryInGlobalFreeList()
Always returns 0, since no blocks are allocated.
Definition: MallocMemoryAllocator.h:98
ogdf::MallocMemoryAllocator::MemElem::m_next
MemElem * m_next
Definition: MallocMemoryAllocator.h:43
exceptions.h
Definition of exception classes.
ogdf::InsufficientMemoryException
Exception thrown when not enough memory is available to execute an algorithm.
Definition: exceptions.h:205
ogdf::MallocMemoryAllocator::flushPool
static void flushPool()
Definition: MallocMemoryAllocator.h:84
ogdf::MallocMemoryAllocator::deallocateList
static void deallocateList(size_t, void *pHead, void *pTail)
Deallocate a complete list starting at pHead and ending at pTail.
Definition: MallocMemoryAllocator.h:75
ogdf::MallocMemoryAllocator::memoryInFreelist
static constexpr size_t memoryInFreelist()
Always returns 0, since no blocks are allocated.
Definition: MallocMemoryAllocator.h:95
ogdf::MallocMemoryAllocator::memoryAllocatedInBlocks
static constexpr size_t memoryAllocatedInBlocks()
Always returns 0, since no blocks are allocated.
Definition: MallocMemoryAllocator.h:92
ogdf::MallocMemoryAllocator::checkSize
static constexpr bool checkSize(size_t)
Always returns true since we simply trust malloc().
Definition: MallocMemoryAllocator.h:89
Logger.h
Contains logging functionality.
ogdf::MallocMemoryAllocator::MemElem
Definition: MallocMemoryAllocator.h:42
ogdf::MallocMemoryAllocator::~MallocMemoryAllocator
~MallocMemoryAllocator()
Definition: MallocMemoryAllocator.h:51
OGDF_THROW
#define OGDF_THROW(CLASS)
Replacement for throw.
Definition: exceptions.h:70
ogdf::MallocMemoryAllocator
Implements a simple memory manager using malloc() and free().
Definition: MallocMemoryAllocator.h:41
OGDF_UNLIKELY
#define OGDF_UNLIKELY(x)
Specify the unlikely branch in a condition.
Definition: config.h:230
ogdf::MallocMemoryAllocator::deallocate
static void deallocate(size_t, void *p)
Deallocates memory at address p. We do not keep track of the size of the deallocated object.
Definition: MallocMemoryAllocator.h:69
ogdf::MallocMemoryAllocator::allocate
static void * allocate(size_t nBytes, const char *, int)
Allocates memory of size nBytes.
Definition: MallocMemoryAllocator.h:56
ogdf::MallocMemoryAllocator::MallocMemoryAllocator
MallocMemoryAllocator()
Definition: MallocMemoryAllocator.h:49
ogdf::MallocMemoryAllocator::cleanup
static void cleanup()
Definition: MallocMemoryAllocator.h:53
ogdf::MallocMemoryAllocator::flushPool
static void flushPool(uint16_t)
Definition: MallocMemoryAllocator.h:86
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::MallocMemoryAllocator::allocate
static void * allocate(size_t nBytes)
Allocates memory of size nBytes.
Definition: MallocMemoryAllocator.h:59
ogdf::MallocMemoryAllocator::memoryInThreadFreeList
static constexpr size_t memoryInThreadFreeList()
Always returns 0, since no blocks are allocated.
Definition: MallocMemoryAllocator.h:101