CXXR (C++ R)
|
#include <CellHeap.hpp>
Public Member Functions | |
CellHeap (size_t dbls_per_cell, size_t cells_per_superblock) | |
~CellHeap () | |
void * | allocate () throw (std::bad_alloc) |
Allocate a cell from the heap. | |
size_t | cellSize () const |
unsigned int | cellsAllocated () const |
bool | check () const |
Integrity check. | |
void | deallocate (void *p) |
Deallocate a cell. | |
void * | easyAllocate () throw () |
Allocate a cell 'from stock'. | |
size_t | superblockSize () const |
Class to manage a pool of memory cells of a fixed size.
This class manages a collection of memory cells of a specified size, and is intended as a back-end to implementations of operator new and operator delete to enable the allocation and deallocation of small objects quickly. It differs from CellPool in that it always allocates the cell with the minimum address from among the currently available cells. This is achieved using a skew heap data structure (Sleator and Tarjan 1986). This data structure works most efficiently if cells are as far as possible released in the reverse order of allocation.
|
inline |
dbls_per_cell | (must be >= 1). Size of cells, expressed as a multiple of sizeof(double). For example, if you require cells large enough to contain one double, put dbls_per_cell as 1. (NB: cells can contain anything, not just doubles; we work in doubles because these are likely to have the most stringent address alignment requirements.) |
cells_per_superblock | (must be >= 1). Memory for cells is obtained from the main heap in 'superblocks' sufficient to contain this many cells. |
CellHeap::~CellHeap | ( | ) |
Destructor
It is up to the user to check that any cells allocated from the heap have been freed before this destructor is invoked. (Although the destructor could check this for itself and issue an error message, this message would probably be a nuisance if it occurred during program shutdown.)
|
inline |
Allocate a cell from the heap.
bad_alloc | if a cell cannot be allocated. |
|
inline |
|
inline |
bool CellHeap::check | ( | ) | const |
Integrity check.
Aborts the program with an error message if the object is found to be internally inconsistent.
assert
. void CellHeap::deallocate | ( | void * | p | ) |
Deallocate a cell.
p | Pointer to a block of memory previously allocated from this heap, or a null pointer (in which case method does nothing). |
|
inline |
Allocate a cell 'from stock'.
Allocate a cell from the heap, provided it can be allocated 'from stock'. Can be useful when called from other inlined functions in that it doesn't throw any exceptions.
|
inline |