fixed_pool テンプレート・クラス

概要

固定長バッファーからのスケーラブルなメモリー割り当て用のテンプレート・クラス。

構文

class fixed_pool;

ヘッダー

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

説明

fixed_pool は、プロセッサーの数でスケールするようにメモリーの割り当てと解放を行います。最初に、割り当て可能なすべてのメモリーがコンストラクターの引数で渡されます。fixed_pool はメモリープール・コンセプトをモデル化します。

サンプル

#define TBB_PREVIEW_MEMORY_POOL 1
 #include "tbb/memory_pool.h"
 ...
 char buf[1024*1024];
 tbb::fixed_pool my_pool(buf, 1024*1024);
 void* my_ptr = my_pool.malloc(10);
 my_pool.free(my_ptr);}

上記のコードは、固定プールからの単純な割り当て例です。

メンバー

namespace tbb {
 class fixed_pool : no_copy {
 public:
 fixed_pool(void *buffer, size_t size) throw(std::bad_alloc);
 ~fixed_pool();
 void recycle();
 void *malloc(size_t size);
 void free(void* ptr);
 void *realloc(void* ptr, size_t size);
 };
 }
次の表は、このクラスのメンバーの詳細な情報を提供します。
メンバー 説明
fixed_pool(void *buffer, size_t size)

バッファーが指しているメモリーとそのサイズを管理するためのメモリープールを構築します。

ランタイムにクラスのインスタンスの構築に失敗した場合、bad_alloc 例外をスローします。