cds  2.3.2
cds::memory::pool_allocator< T, Accessor > Class Template Reference

Pool allocator adapter. More...

#include <cds/memory/pool_allocator.h>

Detailed Description

template<typename T, typename Accessor>
class cds::memory::pool_allocator< T, Accessor >

Pool allocator adapter.

This class is an adapter for an object pool. It gives std::allocator interface for the pool.

Template arguments:

  • T - value type
  • Accessor - a functor to access to the pool object. The pool has the following interface:
    template <typename T>
    class pool {
    typedef T value_type ; // Object type maintained by pool
    T * allocate( size_t n ) ; // Allocate an array of object of type T
    void deallocate( T * p, size_t n ) ; // Deallocate the array p of size n
    };

Usage

Suppose, we have a pool with interface above. Usually, the pool is a static object:

static pool<Foo> thePool;

The pool_allocator gives std::allocator interface for the pool. It is needed to declare an accessor functor to access to thePool:

struct pool_accessor {
typedef typename pool::value_type value_type;
pool& operator()() const
{
return thePool;
}
};

Now, cds::memory::pool_allocator< T, pool_accessor > can be used instead of std::allocator.


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

cds 2.3.2 Developed by Maxim Khizhinsky aka khizmax and other contributors 2007 - 2017
Autogenerated Sun Dec 31 2017 12:10:49 by Doxygen 1.8.13