Open
Graph Drawing
Framework

 v.2012.05
 

ogdf::PoolMemoryAllocator Class Reference

The class PoolAllocator represents ogdf's pool memory allocator. More...

#include <ogdf/internal/basic/PoolMemoryAllocator.h>

List of all members.

Classes

struct  MemElem
struct  MemElemEx

Public Types

enum  { eMinBytes = sizeof(MemElemPtr), eTableSize = 256, eBlockSize = 8192, ePoolVectorLength = 15 }

Public Member Functions

 PoolMemoryAllocator ()
 ~PoolMemoryAllocator ()

Static Public Member Functions

static OGDF_EXPORT void init ()
 Initializes the memory manager.
static OGDF_EXPORT void initThread ()
static OGDF_EXPORT void cleanup ()
 Frees all memory blocks allocated by the memory manager.
static OGDF_EXPORT bool checkSize (size_t nBytes)
static OGDF_EXPORT void * allocate (size_t nBytes)
 Allocates memory of size nBytes.
static OGDF_EXPORT void deallocate (size_t nBytes, void *p)
 Deallocates memory at address p which is of size nBytes.
static OGDF_EXPORT void deallocateList (size_t nBytes, void *pHead, void *pTail)
 Deallocate a complete list starting at pHead and ending at pTail.
static OGDF_EXPORT void flushPool ()
static OGDF_EXPORT void flushPool (__uint16 nBytes)
static OGDF_EXPORT size_t memoryAllocatedInBlocks ()
 Returns the total amount of memory (in bytes) allocated from the system.
static OGDF_EXPORT size_t memoryInGlobalFreeList ()
 Returns the total amount of memory (in bytes) available in the global free lists.
static OGDF_EXPORT size_t memoryInThreadFreeList ()
 Returns the total amount of memory (in bytes) available in the thread's free lists.

Private Types

typedef MemElemMemElemPtr
typedef MemElemExMemElemExPtr
typedef BlockChain * BlockChainPtr

Static Private Member Functions

static int slicesPerBlock (__uint16 nBytes)
static int slicesPerBlock (__uint16 nBytes, int &nWords)
static void incVectorSlot (PoolElement &pe)
static void flushPoolSmall (__uint16 nBytes)
static MemElemExPtr collectGroups (__uint16 nBytes, MemElemPtr &pRestHead, MemElemPtr &pRestTail, int &nRest)
static void * fillPool (MemElemPtr &pFreeBytes, __uint16 nBytes)
static MemElemPtr allocateBlock (__uint16 nBytes)

Static Private Attributes

static PoolElement s_pool [eTableSize]
static MemElemPtr s_freeVectors
static BlockChainPtr s_blocks
static CriticalSections_criticalSection
static OGDF_DECL_THREAD MemElemPtr s_tp [eTableSize]

Detailed Description

The class PoolAllocator represents ogdf's pool memory allocator.

Usage:

Adding the macro OGDF_NEW_DELETE in a class declaration overloads new and delete operators of that class such that they use this memory allocator. This is useful if the size of a class is less than PoolAllocator::eTableSize bytes.

Another benefit from the OGDF memory-manager is that it throws an InsufficientMemoryException if no more memory is available. Hence it is legal to omit checking if new returned 0 as long as stack- unwinding frees all memory allocated so far. It is also possible to make the usual new operator behave the same way (throwing an InsufficientMemoryException) by defining the macro OGDF_MALLOC_NEW_DELETE in a class declaration.

Definition at line 79 of file PoolMemoryAllocator.h.


Member Typedef Documentation

typedef BlockChain* ogdf::PoolMemoryAllocator::BlockChainPtr [private]

Definition at line 94 of file PoolMemoryAllocator.h.

Definition at line 90 of file PoolMemoryAllocator.h.

Definition at line 89 of file PoolMemoryAllocator.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
eMinBytes 
eTableSize 
eBlockSize 
ePoolVectorLength 

Definition at line 98 of file PoolMemoryAllocator.h.


Constructor & Destructor Documentation


Member Function Documentation

static OGDF_EXPORT void* ogdf::PoolMemoryAllocator::allocate ( size_t  nBytes) [inline, static]

Allocates memory of size nBytes.

Definition at line 125 of file PoolMemoryAllocator.h.

static MemElemPtr ogdf::PoolMemoryAllocator::allocateBlock ( __uint16  nBytes) [static, private]
static OGDF_EXPORT bool ogdf::PoolMemoryAllocator::checkSize ( size_t  nBytes) [inline, static]

Definition at line 120 of file PoolMemoryAllocator.h.

Frees all memory blocks allocated by the memory manager.

static MemElemExPtr ogdf::PoolMemoryAllocator::collectGroups ( __uint16  nBytes,
MemElemPtr pRestHead,
MemElemPtr pRestTail,
int &  nRest 
) [static, private]
static OGDF_EXPORT void ogdf::PoolMemoryAllocator::deallocate ( size_t  nBytes,
void *  p 
) [inline, static]

Deallocates memory at address p which is of size nBytes.

Definition at line 141 of file PoolMemoryAllocator.h.

static OGDF_EXPORT void ogdf::PoolMemoryAllocator::deallocateList ( size_t  nBytes,
void *  pHead,
void *  pTail 
) [inline, static]

Deallocate a complete list starting at pHead and ending at pTail.

The elements are assumed to be chained using the first word of each element and elements are of size nBytes. This is much more efficient the deallocating each element separately, since the whole chain can be concatenated with the free list, requiring only constant effort.

Definition at line 158 of file PoolMemoryAllocator.h.

static void* ogdf::PoolMemoryAllocator::fillPool ( MemElemPtr pFreeBytes,
__uint16  nBytes 
) [static, private]
static OGDF_EXPORT void ogdf::PoolMemoryAllocator::flushPool ( __uint16  nBytes) [static]
static void ogdf::PoolMemoryAllocator::flushPoolSmall ( __uint16  nBytes) [static, private]
static void ogdf::PoolMemoryAllocator::incVectorSlot ( PoolElement &  pe) [static, private]
static OGDF_EXPORT void ogdf::PoolMemoryAllocator::init ( ) [static]

Initializes the memory manager.

static OGDF_EXPORT void ogdf::PoolMemoryAllocator::initThread ( ) [inline, static]

Definition at line 111 of file PoolMemoryAllocator.h.

Returns the total amount of memory (in bytes) allocated from the system.

Returns the total amount of memory (in bytes) available in the global free lists.

Returns the total amount of memory (in bytes) available in the thread's free lists.

static int ogdf::PoolMemoryAllocator::slicesPerBlock ( __uint16  nBytes) [inline, static, private]

Definition at line 181 of file PoolMemoryAllocator.h.

static int ogdf::PoolMemoryAllocator::slicesPerBlock ( __uint16  nBytes,
int &  nWords 
) [inline, static, private]

Definition at line 186 of file PoolMemoryAllocator.h.


Member Data Documentation

Definition at line 206 of file PoolMemoryAllocator.h.

Definition at line 205 of file PoolMemoryAllocator.h.

PoolElement ogdf::PoolMemoryAllocator::s_pool[eTableSize] [static, private]

Definition at line 204 of file PoolMemoryAllocator.h.

OGDF_DECL_THREAD MemElemPtr ogdf::PoolMemoryAllocator::s_tp[eTableSize] [static, private]

Definition at line 215 of file PoolMemoryAllocator.h.


The documentation for this class was generated from the following file: