|
My Project
|
This class can be used as a custom allocator for stl containers, which constantly create and delete small or medium sized objects. More...
#include <ParaMemPool.h>
Classes | |
| struct | rebind |
| struct | SingletonMemPool_Type |
Public Member Functions | |
| Pool_Char_alloc (Pool_Char_alloc const &) | |
| template<typename U > | |
| Pool_Char_alloc (const Pool_Char_alloc< U, UserAllocator > &) | |
| pointer | address (reference r) |
| const_pointer | address (const_reference r) |
| size_type | max_size () const |
| pointer | allocate (size_type cnt, typename std::allocator< void >::const_pointer=0) |
| void | deallocate (pointer ptr, size_type cnt) |
| void | construct (pointer p, const T &t) |
| void | destroy (pointer p) |
| bool | operator== (Pool_Char_alloc const &) |
| bool | operator!= (Pool_Char_alloc const &a) |
Static Public Attributes | |
| static const int | char_pool_init_size_bytes = 32 |
| the initial smallest fixed sized chunk that the memory pool will create. More... | |
| static const int | char_pool_init_size = 5 |
| this should be log2(char_pool_init_size_bytes) | |
| static const int | char_pool_count = 7 |
| how many free lists are there in the pool. More... | |
| static SingletonMemPool_Type | s_mem_pools |
| predefined memory pool (free lists) | |
This class can be used as a custom allocator for stl containers, which constantly create and delete small or medium sized objects.
it is optimized for frequently used temporary objects. it is faster than std::allocator and boost::pool_alloc. But it costs more (double at most) memory than boost::pool_alloc, because we may return more memory than requested.
Internally, it has 7 free lists (boost::pool). Each free list only serves one fixed-sized object at a time. Each pool has their own light weighted locks for thread-safe access. The free list sizes are 32,64,128,256,512,1024,2048; we will use the default allocator for sizes over 2048. One can configure the internal freelists by editing the macro char_pool_init_size_bytes, char_pool_init_size, char_pool_count
[NOT thread safe]: for a thread safe implementation, refer to CNPLPool_Char_alloc in NPLMemPool.h Example: typedef std::list<void*, Pool_Char_alloc<void*> > MyList;
|
static |
how many free lists are there in the pool.
char_pool_init_size_bytes^2 is the biggest chunk. currently it is 2048 bytes
|
static |
the initial smallest fixed sized chunk that the memory pool will create.
default to 32 bytes
1.8.12