Template class that provides the C++ allocator interface for memory pools.
template<typename T> class memory_pool_allocator;
#define TBB_PREVIEW_MEMORY_POOL 1 #include "tbb/memory_pool.h"
A memory_pool_allocator models the allocator requirements described in Table 29 except for default constructor which is excluded from the class. Instead, it provides a constructor, which links with an instance of memory_pool or fixed_pool classes, that actually allocates and deallocates memory. The class is mainly intended to enable memory pools within STL containers.
#define TBB_PREVIEW_MEMORY_POOL 1 #include "tbb/memory_pool.h" ... typedef tbb::memory_pool_allocator<int> pool_allocator_t; std::list<int, pool_allocator_t> my_list(pool_allocator_t( my_pool ));
The code above provides a simple example of cnostruction of a container that uses a memory pool.
namespace tbb { template<typename T> class memory_pool_allocator { public: typedef T value_type; typedef value_type* pointer; typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; typedef size_t size_type; typedef ptrdiff_t difference_type; template<typename U> struct rebind { typedef memory_pool_allocator<U> other; }; memory_pool_allocator(memory_pool &pool) throw(); memory_pool_allocator(fixed_pool &pool) throw(); memory_pool_allocator(const memory_pool_allocator& src) throw(); template<typename U> memory_pool_allocator(const memory_pool_allocator<U,P>& src) throw(); pointer address(reference x) const; const_pointer address(const_reference x) const; pointer allocate( size_type n, const void* hint=0); void deallocate( pointer p, size_type ); size_type max_size() const throw(); void construct( pointer p, const T& value ); void destroy( pointer p ); }; template<> class memory_pool_allocator<void> { public: typedef void* pointer; typedef const void* const_pointer; typedef void value_type; template<typename U> struct rebind { typedef memory_pool_allocator<U> other; }; memory_pool_allocator(memory_pool &pool) throw(); memory_pool_allocator(fixed_pool &pool) throw(); memory_pool_allocator(const memory_pool_allocator& src) throw(); template<typename U> memory_pool_allocator(const memory_pool_allocator<U>& src) throw(); }; template<typename T, typename U> inline bool operator==( const memory_pool_allocator<T>& a, const memory_pool_allocator<U>& b); template<typename T, typename U> inline bool operator!=( const memory_pool_allocator<T>& a, const memory_pool_allocator<U>& b); }
Member | Description |
---|---|
memory_pool_allocator(memory_pool &pool) |
Constructs memory pool allocator serviced by memory_pool instance pool. |
memory_pool_allocator(fixed_pool &pool) |
Constructs memory pool allocator serviced by fixed_pool instance pool. |