This allocator is intended for use in a multithreaded environment where many short-lived objects are created and released.
Allocations are not thread safe, but deallocations are. This allows each thread to allocate objects cheaply, without worrying about who will eventually deallocate them (they must still be deallocated, of course). To use: give each thread its own allocator: that provides the thread-safety.
The factory is backed by a global dynarray which manages block-level allocation; each block provides N chips to hand out to clients. The allocator maintains a cache of blocks just large enough that it can expect to recycle the oldest cached block as each active block is consumed; the cache can both grow and shrink to match demand.
PROS:
CONS:
Definition at line 202 of file block_alloc.h.
Public Types | |
typedef memory_block::meta_block_size< sizeof(T)> | BlockSize |
Public Member Functions | |
block_pool () | |
void * | acquire () |
Acquire one object(chip) from the pool. | |
void | recycle () |
void | dump () const |
size_t | freelist_size () const |
Static Public Member Functions | |
static size_t | block_size () |
static size_t | chip_count () |
static size_t | chip_size () |
static Pool * | get_static_pool () |
Each block_pool<T> has its own allocator, one per type T. | |
static void | release (void *ptr) |