My Project
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Protected Attributes | List of all members
ParaEngine::CNPLPool_Char_alloc< UserAllocator, Mutex > 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 <NPLMemPool.h>

Classes

struct  rebind
 
struct  SingletonMemPool_Type
 

Public Types

typedef char value_type
 
typedef UserAllocator user_allocator
 
typedef Mutex mutex_type
 
typedef value_type * pointer
 
typedef const value_type * const_pointer
 
typedef value_type & reference
 
typedef const value_type & const_reference
 
typedef ParaEngine::PoolThreadSafe< UserAllocator, Mutexpool_type
 
typedef pool_type::size_type size_type
 
typedef pool_type::difference_type difference_type
 

Public Member Functions

 CNPLPool_Char_alloc (const CNPLPool_Char_alloc< UserAllocator, Mutex > &)
 
bool operator== (const CNPLPool_Char_alloc &) const
 
bool operator!= (const CNPLPool_Char_alloc &) const
 

Static Public Member Functions

static pointer address (reference r)
 
static const_pointer address (const_reference s)
 
static size_type max_size ()
 
static pointer allocate (const size_type n)
 
static pointer allocate (const size_type n, const void *const)
 
static void deallocate (const pointer ptr, const size_type n)
 

Static Protected Attributes

static SingletonMemPool_Type s_mem_pools
 predefined memory pool (free lists)
 

Detailed Description

template<typename UserAllocator, typename Mutex>
class ParaEngine::CNPLPool_Char_alloc< UserAllocator, Mutex >

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 NPL objects, such as NPL related message body, file names, message bodies, etc. 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 NPL_char_pool_init_size_bytes, NPL_char_pool_init_size, NPL_char_pool_count

[thread safe] Example: typedef std::basic_string<char, std::char_traits<char>, ParaEngine::CNPLPool_Char_alloc<> > NPLString;

This is the standard boost version(DONOT use this) #include <boost/pool/pool_alloc.hpp> typedef std::basic_string<char, std::char_traits<char>, boost::pool_allocator > String;


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