Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
MallocMemoryAllocator.h
Go to the documentation of this file.
1
33#pragma once
34
35#include <ogdf/basic/basic.h>
37
38#include <cstdint>
39#include <cstdlib>
40
41namespace ogdf {
42
45 struct MemElem {
47 };
48
50
51public:
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}
Basic declarations, included by all source files.
Exception thrown when not enough memory is available to execute an algorithm.
Definition exceptions.h:209
Implements a simple memory manager using malloc() and free().
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.
static constexpr size_t memoryInFreelist()
Always returns 0, since no blocks are allocated.
static constexpr size_t memoryInThreadFreeList()
Always returns 0, since no blocks are allocated.
static constexpr bool checkSize(size_t)
Always returns true since we simply trust malloc().
static constexpr size_t memoryInGlobalFreeList()
Always returns 0, since no blocks are allocated.
static void deallocate(size_t, void *p)
Deallocates memory at address p. We do not keep track of the size of the deallocated object.
static void deallocateList(size_t, void *pHead, void *pTail)
Deallocate a complete list starting at pHead and ending at pTail.
static void * allocate(size_t nBytes)
Allocates memory of size nBytes.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
Definition of exception classes.
#define OGDF_THROW(CLASS)
Replacement for throw.
Definition exceptions.h:67
#define OGDF_UNLIKELY(x)
Specify the unlikely branch in a condition.
Definition config.h:316
The namespace for all OGDF objects.