CXXR (C++ R)
|
Class to manage memory allocation and deallocation for CXXR. More...
#include <MemoryBank.hpp>
Static Public Member Functions | |
static void * | allocate (size_t bytes) throw (std::bad_alloc) |
Allocate a block of memory. | |
static size_t | blocksAllocated () |
Number of blocks currently allocated. | |
static size_t | bytesAllocated () |
Number of bytes currently allocated. | |
static void | check () |
Integrity check. | |
static void | deallocate (void *p, size_t bytes) |
Deallocate a block. | |
static void | defragment () |
Reorganise lists of free cells. |
Friends | |
class | SchwarzCounter< MemoryBank > |
Class to manage memory allocation and deallocation for CXXR.
Small objects are quickly allocated from pools of various cell sizes; large objects are obtained directly from the main heap.
If the class is compiled with the FILL55 preprocessor variable defined, released memory blocks are filled with 0x55 bytes (though some of these may be overwritten by data used for free list management). This can be useful to show up premature deallocation of memory block, especially if used in conjunction with the CELLFIFO preprocessor variable documented in config.hpp .
|
static |
Allocate a block of memory.
bytes | Required size in bytes of the block. |
bad_alloc | if a cell cannot be allocated. |
|
inlinestatic |
Number of blocks currently allocated.
|
inlinestatic |
Number of bytes currently allocated.
|
static |
Integrity check.
Aborts the program with an error message if the class is found to be internally inconsistent.
|
inlinestatic |
Deallocate a block.
p | Pointer to a block of memory previously allocated by MemoryBank::allocate(), or a null pointer (in which case method does nothing). |
bytes | The number of bytes in the memory block, i.e. the number of bytes requested in the corresponding call to allocate(). |
|
static |
Reorganise lists of free cells.
This is done with a view to increasing the probability that successive allocations will lie within the same cache line or (less importantly nowadays) memory page.