CXXR (C++ R)
Static Public Member Functions | Friends
CXXR::MemoryBank Class Reference

Class to manage memory allocation and deallocation for CXXR. More...

#include <MemoryBank.hpp>

List of all members.

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 >

Detailed Description

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 .


Member Function Documentation

void * MemoryBank::allocate ( size_t  bytes) throw (std::bad_alloc)
static

Allocate a block of memory.

Parameters:
bytesRequired size in bytes of the block.
Returns:
a pointer to the allocated cell.
Exceptions:
bad_allocif a cell cannot be allocated.
static size_t CXXR::MemoryBank::blocksAllocated ( )
inlinestatic

Number of blocks currently allocated.

Returns:
the number of blocks of memory currently allocated.
static size_t CXXR::MemoryBank::bytesAllocated ( )
inlinestatic

Number of bytes currently allocated.

Returns:
the number of bytes of memory currently allocated.
Note:
This refers to the total number of bytes requested in blocks that have been allocated but not subsequently deallocated. Actual utilisation of memory in the main heap may be greater than this, possibly by as much as a factor of 2.
void MemoryBank::check ( )
static

Integrity check.

Aborts the program with an error message if the class is found to be internally inconsistent.

static void CXXR::MemoryBank::deallocate ( void *  p,
size_t  bytes 
)
inlinestatic

Deallocate a block.

Parameters:
pPointer to a block of memory previously allocated by MemoryBank::allocate(), or a null pointer (in which case method does nothing).
bytesThe number of bytes in the memory block, i.e. the number of bytes requested in the corresponding call to allocate().
void MemoryBank::defragment ( )
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.


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