My Project
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
ParaEngine::Pool_Char_alloc< T, UserAllocator > Class Template Reference

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 Types

typedef T value_type
 
typedef UserAllocator user_allocator
 
typedef value_type * pointer
 
typedef const value_type * const_pointer
 
typedef value_type & reference
 
typedef const value_type & const_reference
 
typedef boost::pool< UserAllocator > pool_type
 
typedef pool_type::size_type size_type
 
typedef pool_type::difference_type difference_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)
 

Detailed Description

template<typename T, typename UserAllocator>
class ParaEngine::Pool_Char_alloc< T, UserAllocator >

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;

Member Data Documentation

§ char_pool_count

template<typename T , typename UserAllocator >
const int ParaEngine::Pool_Char_alloc< T, UserAllocator >::char_pool_count = 7
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

§ char_pool_init_size_bytes

template<typename T , typename UserAllocator >
const int ParaEngine::Pool_Char_alloc< T, UserAllocator >::char_pool_init_size_bytes = 32
static

the initial smallest fixed sized chunk that the memory pool will create.

default to 32 bytes


The documentation for this class was generated from the following file: