Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

base::DataAllocator Class Reference

Fast chunk allocator. More...

#include <DataAllocator.h>

Inheritance diagram for base::DataAllocator:

base::Object List of all members.

Public Member Functions

 DataAllocator ()
 constructor: allocate a pool
 ~DataAllocator ()
 destructor: deallocate all pools
void * allocate (size_t intSize)
 allocate memory: take memory
  • on the free list first
  • or on the pool if there is space left
  • or allocate a new pool

void deallocate (void *data, size_t intSize)
 Deallocate: store in the free list.
void reset ()
 Deallocate all pools except the base.
void printStats (FILE *out) const
 Print statistics, C style = wrapper to C++.
std::ostream & printStats (std::ostream &out) const
 Print statistics.
allocator_t getCAllocator ()
 C wrapper allocator.

Private Types

enum  { CHUNK_SIZE = (1 << 22) }
 Memory is allocated internally by chunks. More...

Private Member Functions

bool hasInPools (const uintptr_t *data, size_t intSize) const
 Check that a given address belongs to a pool or the free list.

Static Private Member Functions

static uintptr_t * getNext (uintptr_t data)
 An entry in the freeMem table at i gives a free memory block of size i ints.
static uintptr_t getNext (uintptr_t *data)

Private Attributes

array_t< uintptr_t * > freeMem
 Table of free memory lists.
Pool_tmemPool
 current pool in use
uintptr_t * freePtr
 current free mem position
uintptr_t * endFree
 end of current chunk

Classes

struct  Pool_t
 Memory pool. More...

Detailed Description

Fast chunk allocator.

Has the ability to deallocate all data at once.


Member Enumeration Documentation

anonymous enum [private]
 

Memory is allocated internally by chunks.

This controls the size of these chunks.

Enumeration values:
CHUNK_SIZE 


Constructor & Destructor Documentation

base::DataAllocator::DataAllocator  ) 
 

constructor: allocate a pool

base::DataAllocator::~DataAllocator  ) 
 

destructor: deallocate all pools


Member Function Documentation

void * base::DataAllocator::allocate size_t  intSize  ) 
 

allocate memory: take memory

  • on the free list first
  • or on the pool if there is space left
  • or allocate a new pool

Parameters:
intSize,: size in int units
Returns:
a int32[intSize] allocated memory area. If ALIGN_WORD64 is defined then the result is aligned on 64 bits. It is the responsability of the developper to use the flag. It is possible to skip the flag on Intel architecture that can cope with non aligned addresses.
Precondition:
intSize <= CHUNK_SIZE

void base::DataAllocator::deallocate void *  data,
size_t  intSize
 

Deallocate: store in the free list.

Precondition:
  • memory was allocated with allocate
  • size allocated was intSize
Parameters:
data,: memory to deallocate
intSize,: size in int units of the allocated memory.

allocator_t base::DataAllocator::getCAllocator  )  [inline]
 

C wrapper allocator.

Returns:
C wrapper allocator_t

static uintptr_t base::DataAllocator::getNext uintptr_t *  data  )  [inline, static, private]
 

static uintptr_t* base::DataAllocator::getNext uintptr_t  data  )  [inline, static, private]
 

An entry in the freeMem table at i gives a free memory block of size i ints.

If there are other such blocks, then this memory block contains the pointer to the next free block. This function is a convenience cast for this case.

bool base::DataAllocator::hasInPools const uintptr_t *  data,
size_t  intSize
const [private]
 

Check that a given address belongs to a pool or the free list.

Used for debugging, this is not a performance critical method.

Parameters:
data,: memory to check,
intSize,: size of the memory to check.
Returns:
true if the memory belongs to a pool.

std::ostream & base::DataAllocator::printStats std::ostream &  out  )  const
 

Print statistics.

Parameters:
out,: where to print.
Returns:
the ostream.

void base::DataAllocator::printStats FILE *  out  )  const
 

Print statistics, C style = wrapper to C++.

Parameters:
out,: where to print.

void base::DataAllocator::reset  ) 
 

Deallocate all pools except the base.


Member Data Documentation

uintptr_t* base::DataAllocator::endFree [private]
 

end of current chunk

array_t<uintptr_t*> base::DataAllocator::freeMem [private]
 

Table of free memory lists.

freeMem[i] starts a list of free memory blocks of i INT size

uintptr_t* base::DataAllocator::freePtr [private]
 

current free mem position

Pool_t* base::DataAllocator::memPool [private]
 

current pool in use


The documentation for this class was generated from the following files:
Generated on Fri Jun 30 00:02:30 2006 for Module base by  doxygen 1.4.2