Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

memory.h File Reference

Declaration of memory manager for allocating small pieces of memory. More...

Go to the source code of this file.

Classes

struct  ogdf::OGDFAllocator< T >
 Encapsulates OGDF_ALLOCATOR in a class that can be used as the Allocator for containers of the C++ standard library. More...
 

Namespaces

 ogdf
 The namespace for all OGDF objects.
 

Macros

Managing memory
#define OGDF_ALLOCATOR   ogdf::PoolMemoryAllocator
 The used memory manager. More...
 
#define OGDF_MALLOC_NEW_DELETE   OGDF_MM(ogdf::MallocMemoryAllocator)
 Makes the class use malloc for memory allocation. More...
 
#define OGDF_MM(Alloc)
 Creates new and delete operators in a class using the given memory allocator. More...
 
#define OGDF_NEW_DELETE   OGDF_MM(OGDF_ALLOCATOR)
 Makes the class use OGDF's memory allocator. More...
 

Detailed Description

Declaration of memory manager for allocating small pieces of memory.

Author
Carsten Gutwenger
License:
This file is part of the Open Graph Drawing Framework (OGDF).
Copyright (C)
See README.md in the OGDF root directory for details.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License Version 2 or 3 as published by the Free Software Foundation; see the file LICENSE.txt included in the packaging of this file for details.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, see http://www.gnu.org/copyleft/gpl.html

Definition in file memory.h.

Macro Definition Documentation

◆ OGDF_ALLOCATOR

#define OGDF_ALLOCATOR   ogdf::PoolMemoryAllocator

The used memory manager.

Definition at line 77 of file memory.h.

◆ OGDF_MM

#define OGDF_MM (   Alloc)
Value:
public: \
static void* operator new(size_t nBytes) { \
if (OGDF_LIKELY(Alloc::checkSize(nBytes))) \
return Alloc::allocate(nBytes); \
else \
} \
\
static void operator delete(void* p, size_t nBytes) { \
if (OGDF_LIKELY(p != 0)) { \
if (OGDF_LIKELY(Alloc::checkSize(nBytes))) \
Alloc::deallocate(nBytes, p); \
else \
ogdf::MallocMemoryAllocator::deallocate(nBytes, p); \
} \
} \
static void* operator new(size_t, void* p) { return p; } \
static void operator delete(void*, void*) { }

Creates new and delete operators in a class using the given memory allocator.

In other words, adding this macro in a class declaration makes that class managed by the respective memory manager. Throws an ogdf::InsufficientMemoryException if no more memory is available.

Definition at line 53 of file memory.h.

OGDF_LIKELY
#define OGDF_LIKELY(x)
Specify the likely branch in a condition.
Definition: config.h:223
ogdf::MallocMemoryAllocator::allocate
static void * allocate(size_t nBytes, const char *, int)
Allocates memory of size nBytes.
Definition: MallocMemoryAllocator.h:59