scalable_allocator
[memory_allocation.scalable_allocator]
scalable_allocator は、[allocator.requirements] ISO C++ セクションのアロケーター要件をモデル化するクラス・テンプレートです。
scalable_allocator は、プロセッサー数に応じてメモリーを割り当て、そして解放します。scalable_allocator で割り当てられたメモリーは、std::allocator ではなく、scalable_allocator で解放する必要があります。
// <oneapi/tbb/scalable_allocator.h> ヘッダーで定義
namespace oneapi {
namespace tbb {
template<typename T> class scalable_allocator {
public:
using value_type = T;
using size_type = std::size_t;
using propagate_on_container_move_assignment = std::true_type;
using is_always_equal = std::true_type;
scalable_allocator() = default;
template<typename U>
scalable_allocator(const scalable_allocator<U>&) noexcept;
T* allocate(size_type);
void deallocate(T*, size_type);
};
} // namespace tbb
} // namespace oneapi警告
scalable_allocator を使用するには、メモリー・アロケーター・ライブラリーが必要です。ライブラリーが利用できない場合、スケーラブル・アロケーターの呼び出しは失敗します。scalable_allocator とは対照的に、メモリー・アロケーター・ライブラリーが利用できない場合、tbb_allocator は std::malloc および std::free にフォールバックします。
メンバー関数
- value_type *allocate(size_type n)
n * sizeof(T)バイトのメモリーを割り当てます。割り当てられたメモリーへのポインターを返します。
- void deallocate(value_type *p, size_type n)
pが指すメモリー割り当てを解除します。ポインターpがallocate(n)メソッドの結果でない場合の動作は未定義です。メモリーがすでに割り当て解除されている場合の動作は未定義です。
非メンバー関数
これらの関数は、2 つの scalable_allocator インスタンスの比較操作を提供します。
namespace oneapi {
namespace tbb {
template<typename T, typename U>
bool operator==(const scalable_allocator<T>&,
const scalable_allocator<U>&) noexcept;
template<typename T, typename U>
bool operator!=(const scalable_allocator<T>&,
const scalable_allocator<U>&) noexcept;
} // namespace tbb
} // namespace oneapiこれらの関数が scalable_allocator オブジェクトの二項演算式で使用できる限り、これらの関数が定義される名前空間を指定する必要はありません。例えば、実装では同じ未指定の名前空間でクラスと関数を定義し oneapi::tbb::scalable_allocator をタイプエイリアスとして定義できます。この場合、非メンバー関数には引数依存のルックアップによってのみ到達できます。
