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/basic.h>
36 #include <ogdf/basic/exceptions.h>
37 
38 #include <cstdint>
39 #include <cstdlib>
40 
41 namespace ogdf {
42 
45  struct MemElem {
47  };
48 
49  using MemElemPtr = MemElem*;
50 
51 public:
53 
55 
56  static void cleanup() { }
57 
59  static inline void* allocate(size_t nBytes, const char*, int) { return allocate(nBytes); }
60 
62  static inline void* allocate(size_t nBytes) {
63  void* p = malloc(nBytes);
64  if (OGDF_UNLIKELY(p == nullptr)) {
66  }
67  return p;
68  }
69 
72  static inline void deallocate(size_t, void* p) { free(p); }
73 
75 
78  static void deallocateList(size_t /* nBytes */, void* pHead, void* pTail) {
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 
89  static void flushPool(uint16_t /* nBytes */) { }
90 
92  static constexpr bool checkSize(size_t) { return true; }
93 
95  static constexpr size_t memoryAllocatedInBlocks() { return 0; }
96 
98  static constexpr size_t memoryInFreelist() { return 0; }
99 
101  static constexpr size_t memoryInGlobalFreeList() { return 0; }
102 
104  static constexpr size_t memoryInThreadFreeList() { return 0; }
105 };
106 
107 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::MallocMemoryAllocator::memoryInGlobalFreeList
static constexpr size_t memoryInGlobalFreeList()
Always returns 0, since no blocks are allocated.
Definition: MallocMemoryAllocator.h:101
ogdf::MallocMemoryAllocator::MemElem::m_next
MemElem * m_next
Definition: MallocMemoryAllocator.h:46
exceptions.h
Definition of exception classes.
ogdf::InsufficientMemoryException
Exception thrown when not enough memory is available to execute an algorithm.
Definition: exceptions.h:209
ogdf::MallocMemoryAllocator::flushPool
static void flushPool()
Definition: MallocMemoryAllocator.h:87
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:78
ogdf::MallocMemoryAllocator::memoryInFreelist
static constexpr size_t memoryInFreelist()
Always returns 0, since no blocks are allocated.
Definition: MallocMemoryAllocator.h:98
ogdf::MallocMemoryAllocator::memoryAllocatedInBlocks
static constexpr size_t memoryAllocatedInBlocks()
Always returns 0, since no blocks are allocated.
Definition: MallocMemoryAllocator.h:95
ogdf::MallocMemoryAllocator::checkSize
static constexpr bool checkSize(size_t)
Always returns true since we simply trust malloc().
Definition: MallocMemoryAllocator.h:92
ogdf::MallocMemoryAllocator::MemElem
Definition: MallocMemoryAllocator.h:45
ogdf::MallocMemoryAllocator::~MallocMemoryAllocator
~MallocMemoryAllocator()
Definition: MallocMemoryAllocator.h:54
OGDF_THROW
#define OGDF_THROW(CLASS)
Replacement for throw.
Definition: exceptions.h:74
ogdf::MallocMemoryAllocator
Implements a simple memory manager using malloc() and free().
Definition: MallocMemoryAllocator.h:44
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:72
ogdf::MallocMemoryAllocator::allocate
static void * allocate(size_t nBytes, const char *, int)
Allocates memory of size nBytes.
Definition: MallocMemoryAllocator.h:59
ogdf::MallocMemoryAllocator::MallocMemoryAllocator
MallocMemoryAllocator()
Definition: MallocMemoryAllocator.h:52
ogdf::MallocMemoryAllocator::cleanup
static void cleanup()
Definition: MallocMemoryAllocator.h:56
ogdf::MallocMemoryAllocator::flushPool
static void flushPool(uint16_t)
Definition: MallocMemoryAllocator.h:89
basic.h
Basic declarations, included by all source files.
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:62
ogdf::MallocMemoryAllocator::memoryInThreadFreeList
static constexpr size_t memoryInThreadFreeList()
Always returns 0, since no blocks are allocated.
Definition: MallocMemoryAllocator.h:104