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

base::ItemAllocator< ITEM > Class Template Reference

Simple (and fast) item allocator. More...

#include <ItemAllocator.h>

List of all members.

Public Types

enum  { NB_ITEMS = (1 << 17) }
 Default number of items. More...

Public Member Functions

 ItemAllocator (size_t nbItems=NB_ITEMS)
 Constructor: check precondition & init to NULL.
 ~ItemAllocator ()
 Destructor = reset.
ITEM * allocate ()
 Allocate a new item.
void deallocate (ITEM *item)
 Deallocate an item.
void reset ()
 Reset the allocator: free all pools and reset the list of free items.

Private Member Functions

void addPool ()
 Add a new pool of items.

Private Attributes

size_t numberOfItems
 number of items per pool
AllocPool_tpool
 allocated pools
AllocCell_tfreeItem
 list of free items

Classes

union  AllocCell_t
 UNION to manage list of free items (next) and allocation of items (item). More...
struct  AllocPool_t
 Pool of items. More...


Detailed Description

template<class ITEM>
class base::ItemAllocator< ITEM >

Simple (and fast) item allocator.

The interest of it, compared to DataAllocator is to have a different memory area (and thus avoid messing up with the pages) for another kind of data. This is particularly fitted to the waiting queue vs explored states stored.

Working of ItemAllocator: it allocates a continuous chunk of numberOfItems items (=pool) and initializes the list of free items. Allocation and deallocation just pop and push items on this list. When the list is empty, a new pool of items is allocated. Template arguments:

Parameters:
ITEM,: type of object to allocate Default = 128k items
Precondition:
ITEM size is at least 1 int.


Member Enumeration Documentation

template<class ITEM>
anonymous enum
 

Default number of items.

Enumeration values:
NB_ITEMS 


Constructor & Destructor Documentation

template<class ITEM>
base::ItemAllocator< ITEM >::ItemAllocator size_t  nbItems = NB_ITEMS  )  [inline]
 

Constructor: check precondition & init to NULL.

Parameters:
nbItems,: number of items per pool.
Precondition:
nbItems > 1

template<class ITEM>
base::ItemAllocator< ITEM >::~ItemAllocator  )  [inline]
 

Destructor = reset.


Member Function Documentation

template<class ITEM>
void base::ItemAllocator< ITEM >::addPool  )  [inline, private]
 

Add a new pool of items.

template<class ITEM>
ITEM* base::ItemAllocator< ITEM >::allocate  )  [inline]
 

Allocate a new item.

Returns:
new allocated item.
Postcondition:
result != NULL

template<class ITEM>
void base::ItemAllocator< ITEM >::deallocate ITEM *  item  )  [inline]
 

Deallocate an item.

Parameters:
item,: item to deallocate.
Precondition:
  • item allocated with this allocator
  • item != NULL

template<class ITEM>
void base::ItemAllocator< ITEM >::reset  )  [inline]
 

Reset the allocator: free all pools and reset the list of free items.


Member Data Documentation

template<class ITEM>
AllocCell_t* base::ItemAllocator< ITEM >::freeItem [private]
 

list of free items

template<class ITEM>
size_t base::ItemAllocator< ITEM >::numberOfItems [private]
 

number of items per pool

template<class ITEM>
AllocPool_t* base::ItemAllocator< ITEM >::pool [private]
 

allocated pools


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