#include <ItemAllocator.h>
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_t * | pool |
allocated pools | |
AllocCell_t * | freeItem |
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... |
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:
ITEM,: | type of object to allocate Default = 128k items |
|
Default number of items.
|
|
Constructor: check precondition & init to NULL.
|
|
Destructor = reset.
|
|
Add a new pool of items.
|
|
Allocate a new item.
|
|
Deallocate an item.
|
|
Reset the allocator: free all pools and reset the list of free items.
|
|
list of free items
|
|
number of items per pool
|
|
allocated pools
|