FEDEM Model Database  R8.0
Source code of the FEDEM model database
Public Member Functions | List of all members
FFaMemPool Class Reference

Class to streamline efficient memory allocation. More...

#include <FFaMemPool.H>

Public Member Functions

 FFaMemPool (size_t objSize, FFaMemPoolMgr *mgr=NULL, int blockSize=512)
 The constructor intializes the data members. More...
 
 FFaMemPool (const FFaMemPool &mempool)
 Copy constructor. More...
 
 ~FFaMemPool ()
 The destructor releases all heap-allocated memory. More...
 
void * doNew (size_t objSize)
 Allocates a chunk of memory of size objSize. More...
 
void doDelete (void *p, size_t objSize)
 Deallocates a memory chunk. More...
 
void freePool (bool release=false)
 Releases all heap-allocated memory in this pool. More...
 
void freePartOfPool (void *objPtrAsId)
 Releases heap-allocated memory associated with specified object. More...
 
void usePartOfPool (void *objPtrAsId)
 Finds or creates a memory pool for specified object. More...
 
void useDefaultPartOfPool ()
 Resets the current memory pool the default instance. More...
 

Detailed Description

Class to streamline efficient memory allocation.

This class is used to help the programmer to reimplement the operators new and delete for small classes that will be instantiated a lot of times. To use, simply make a static member of FFaMemPool in your class, reimplement the operators new and delete in that class by forwarding the calls to FFaMemPool::doNew() and FFaMemPool::doDelete(), respectively:

class foo
{
public:
static void* operator new(size_t n) { return ourMemPool.doNew(n); }
static void operator delete(void* p, size_t n) { ourMemPool.doDelete(p,n); }
static void freePool() { ourMemPool.freePool(); }
private:
static FFaMemPool ourMemPool;
};
Streamlined efficient memory allocation.
Class to streamline efficient memory allocation.
Definition: FFaMemPool.H:60
void freePool(bool release=false)
Releases all heap-allocated memory in this pool.
Definition: FFaMemPool.C:100

In the implementation file :

FFaMemPool foo::ourMemPool(sizeof(foo));
Note
The private members of this class are not documented.
Author
Jacob Storen

Constructor & Destructor Documentation

◆ FFaMemPool() [1/2]

FFaMemPool::FFaMemPool ( size_t  objSize,
FFaMemPoolMgr *  mgr = NULL,
int  blockSize = 512 
)
explicit

The constructor intializes the data members.

◆ FFaMemPool() [2/2]

FFaMemPool::FFaMemPool ( const FFaMemPool &  mempool)

Copy constructor.

◆ ~FFaMemPool()

FFaMemPool::~FFaMemPool ( )

The destructor releases all heap-allocated memory.

Member Function Documentation

◆ doDelete()

void FFaMemPool::doDelete ( void *  p,
size_t  objSize 
)

Deallocates a memory chunk.

◆ doNew()

void * FFaMemPool::doNew ( size_t  objSize)

Allocates a chunk of memory of size objSize.

◆ freePartOfPool()

void FFaMemPool::freePartOfPool ( void *  objPtrAsId)

Releases heap-allocated memory associated with specified object.

◆ freePool()

void FFaMemPool::freePool ( bool  release = false)

Releases all heap-allocated memory in this pool.

◆ useDefaultPartOfPool()

void FFaMemPool::useDefaultPartOfPool ( )
inline

Resets the current memory pool the default instance.

◆ usePartOfPool()

void FFaMemPool::usePartOfPool ( void *  objPtrAsId)

Finds or creates a memory pool for specified object.


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