Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize > Class Template Reference

The singleton_pool class allows other pool interfaces for types of the same size to share the same pool. More...

#include <singleton_pool.hpp>

Public Types

typedef Tag tag
 The Tag template parameter uniquely identifies this pool and allows different unbounded sets of singleton pools to exist. More...
 
typedef Mutex mutex
 The type of mutex used to synchonise access to this pool (default details::pool::default_mutex). More...
 
typedef UserAllocator user_allocator
 The user-allocator used by this pool, default = default_user_allocator_new_delete. More...
 
typedef pool< UserAllocator >
::size_type 
size_type
 size_type of user allocator. More...
 
typedef pool< UserAllocator >
::difference_type 
difference_type
 difference_type of user allocator. More...
 

Public Member Functions

 BOOST_STATIC_CONSTANT (unsigned, requested_size=RequestedSize)
 The size of each chunk allocated by this pool. More...
 
 BOOST_STATIC_CONSTANT (unsigned, next_size=NextSize)
 The number of chunks to allocate on the first allocation. More...
 

Static Public Member Functions

static void *malloc BOOST_PREVENT_MACRO_SUBSTITUTION ()
 
static void * ordered_malloc ()
 
static void * ordered_malloc (const size_type n)
 
static bool is_from (void *const ptr)
 
static void free BOOST_PREVENT_MACRO_SUBSTITUTION (void *const ptr)
 
static void ordered_free (void *const ptr)
 
static void free BOOST_PREVENT_MACRO_SUBSTITUTION (void *const ptr, const size_type n)
 
static void ordered_free (void *const ptr, const size_type n)
 
static bool release_memory ()
 
static bool purge_memory ()
 

Detailed Description

template<typename Tag, unsigned RequestedSize, typename UserAllocator, typename Mutex, unsigned NextSize, unsigned MaxSize>
class boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >

The singleton_pool class allows other pool interfaces for types of the same size to share the same pool.

Template parameters are as follows:

Tag User-specified type to uniquely identify this pool: allows different unbounded sets of singleton pools to exist.

RequestedSize The size of each chunk returned by member function malloc().

UserAllocator User allocator, default = default_user_allocator_new_delete.

Mutex This class is the type of mutex to use to protect simultaneous access to the underlying Pool. Can be any Boost.Thread Mutex type or boost::details::pool::null_mutex. It is exposed so that users may declare some singleton pools normally (i.e., with synchronization), but some singleton pools without synchronization (by specifying boost::details::pool::null_mutex) for efficiency reasons. The member typedef mutex exposes the value of this template parameter. The default for this parameter is boost::details::pool::default_mutex which is a synonym for either boost::details::pool::null_mutex (when threading support is turned off in the compiler (so BOOST_HAS_THREADS is not set), or threading support has ben explicitly disabled with BOOST_DISABLE_THREADS (Boost-wide disabling of threads) or BOOST_POOL_NO_MT (this library only)) or for boost::mutex (when threading support is enabled in the compiler).

NextSize The value of this parameter is passed to the underlying Pool when it is created and specifies the number of chunks to allocate in the first allocation request (defaults to 32). The member typedef static const value next_size exposes the value of this template parameter.

MaxSizeThe value of this parameter is passed to the underlying Pool when it is created and specifies the maximum number of chunks to allocate in any single allocation request (defaults to 0).

Notes:

The underlying pool p referenced by the static functions in singleton_pool is actually declared in a way that is:

1 Thread-safe if there is only one thread running before main() begins and after main() ends – all of the static functions of singleton_pool synchronize their access to p.

2 Guaranteed to be constructed before it is used – thus, the simple static object in the synopsis above would actually be an incorrect implementation. The actual implementation to guarantee this is considerably more complicated.

3 Note too that a different underlying pool p exists for each different set of template parameters, including implementation-specific ones.

4 The underlying pool is constructed "as if" by:

pool<UserAllocator> p(RequestedSize, NextSize, MaxSize);

Attention
The underlying pool constructed by the singleton is never freed. This means that memory allocated by a singleton_pool can be still used after main() has completed, but may mean that some memory checking programs will complain about leaks from singleton_pool.

Member Typedef Documentation

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
typedef pool<UserAllocator>::difference_type boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::difference_type

difference_type of user allocator.

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
typedef Mutex boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::mutex

The type of mutex used to synchonise access to this pool (default details::pool::default_mutex).

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
typedef pool<UserAllocator>::size_type boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::size_type

size_type of user allocator.

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
typedef Tag boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::tag

The Tag template parameter uniquely identifies this pool and allows different unbounded sets of singleton pools to exist.

For example, the pool allocators use two tag classes to ensure that the two different allocator types never share the same underlying singleton pool. Tag is never actually used by singleton_pool.

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
typedef UserAllocator boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::user_allocator

The user-allocator used by this pool, default = default_user_allocator_new_delete.

Member Function Documentation

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
static void* malloc boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::BOOST_PREVENT_MACRO_SUBSTITUTION ( )
inlinestatic

Equivalent to SingletonPool::p.malloc(); synchronized.

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
static void free boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::BOOST_PREVENT_MACRO_SUBSTITUTION ( void *const  ptr)
inlinestatic

Equivalent to SingletonPool::p.free(chunk); synchronized.

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
static void free boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::BOOST_PREVENT_MACRO_SUBSTITUTION ( void *const  ptr,
const size_type  n 
)
inlinestatic

Equivalent to SingletonPool::p.free(chunk, n); synchronized.

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::BOOST_STATIC_CONSTANT ( unsigned  ,
requested_size  = RequestedSize 
)

The size of each chunk allocated by this pool.

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::BOOST_STATIC_CONSTANT ( unsigned  ,
next_size  = NextSize 
)

The number of chunks to allocate on the first allocation.

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
static bool boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::is_from ( void *const  ptr)
inlinestatic

Equivalent to SingletonPool::p.is_from(chunk); synchronized.

Returns
true if chunk is from SingletonPool::is_from(chunk)
template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
static void boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::ordered_free ( void *const  ptr)
inlinestatic

Equivalent to SingletonPool::p.ordered_free(chunk); synchronized.

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
static void boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::ordered_free ( void *const  ptr,
const size_type  n 
)
inlinestatic

Equivalent to SingletonPool::p.ordered_free(chunk, n); synchronized.

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
static void* boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::ordered_malloc ( )
inlinestatic

Equivalent to SingletonPool::p.ordered_malloc(); synchronized.

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
static void* boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::ordered_malloc ( const size_type  n)
inlinestatic

Equivalent to SingletonPool::p.ordered_malloc(n); synchronized.

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
static bool boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::purge_memory ( )
inlinestatic

Equivalent to SingletonPool::p.purge_memory(); synchronized.

template<typename Tag , unsigned RequestedSize, typename UserAllocator , typename Mutex , unsigned NextSize, unsigned MaxSize>
static bool boost::singleton_pool< Tag, RequestedSize, UserAllocator, Mutex, NextSize, MaxSize >::release_memory ( )
inlinestatic

Equivalent to SingletonPool::p.release_memory(); synchronized.


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