memory_pool_allocator テンプレート・クラス

概要

メモリープール用の C++ アロケーター・インターフェイスを提供するテンプレート・クラス。

構文

template<typename T> class memory_pool_allocator;

ヘッダー

#define TBB_PREVIEW_MEMORY_POOL 1
 #include "tbb/memory_pool.h"

説明

memory_pool_allocator は、メモリープール・コンセプト・テーブルのアロケーター要件をモデル化します。ただし、アロケーター要件のデフォルト・コンストラクターの代わりに、実際にメモリーの割り当ておよび割り当て解除を行う、memory_pool クラスまたは fixed_pool クラスのインスタンスとリンクするコンストラクターを提供します。このクラスは、STL コンテナー内でメモリープールを有効にすることを主な目的としています。

サンプル

#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 ));

上記のコードは、メモリープールを使用するコンテナーの構築方法を示す単純な例です。

メンバー

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);
 }
次の表は、このテンプレート・クラスのメンバーの詳細な情報を提供します。
メンバー 説明
memory_pool_allocator(memory_pool &pool)

memory_pool インスタンスで使用されるメモリープール・アロケーターを構築します。

memory_pool_allocator(fixed_pool &pool)

fixed_pool インスタンスで使用されるメモリープール・アロケーターを構築します。