concurrent_lru_cache#
注
この機能を有効にするには、TBB_PREVIEW_CONCURRENT_LRU_CACHE マクロを 1 に定義します。
並行操作を実行する LRU キャッシュのクラス・テンプレート。
説明#
concurrent_lru_cache コンテナーは、キーを値にマッピングし、保存される未使用の値の数を制限する機能を備えています。各キーごとに、コンテナーに格納される項目は最大 1 つです。
コンテナーでは、複数のスレッドが並行にコンテナーからアイテムを取得できます。
コンテナーは、値ではなく項目を参照するプロキシーのconcurrent_lru_cache::handle オブジェクトを返すことで使用中のアイテムを追跡します。項目への参照を保持する handle オブジェクトがなくなると、その項目は未使用とみなされます。
コンテナーには、現在使用中のすべての項目と、限定数の未使用の項目が保存されます。使用されていない項目が多すぎると、LRU (最近最も使用されていない) ポリシーに従って消去されます。
特定のキーに該当する項目が見つからない場合、コンテナーはユーザー指定の value_function_type オブジェクトを呼び出してキーの値を構築し保存します。value_function_type オブジェクトはスレッドセーフである必要があります。
API#
ヘッダー#
#include "oneapi/tbb/concurrent_lru_cache.h"概要#
namespace oneapi {
namespace tbb {
template <typename Key, typename Value, typename ValueFunctionType = Value (*)(Key)>
class concurrent_lru_cache {
public:
using key_type = Key;
using value_type = Value;
using pointer = value_type*;
using const_pointer = const value_type*;
using reference = value_type&;
using const_reference = const value_type&;
using value_function_type = ValueFunctionType;
class handle {
public:
handle();
handle( handle&& other );
~handle();
handle& operator=( handle&& other );
operator bool() const;
value_type& value();
}; // class handle
concurrent_lru_cache( value_function_type f, std::size_t number_of_lru_history_items );
~concurrent_lru_cache();
handle operator[]( key_type key );
}; // class concurrent_lru_cache
} // namespace tbb
} // namespace oneapiメンバー関数
- concurrent_lru_cache(value_function_type f, std::size_t number_of_lru_history_items);#
効果: 新しい値を構築する関数オブジェクト
fを使用して、最大number_of_lru_history_items個の未使用の値を保持できる空のキャッシュを構築します。
- ~concurrent_lru_cache();#
効果:
concurrent_lru_cacheを破棄します。ストアされた要素のデストラクターを呼び出してストレージの割り当てを解除します。
*this と並行操作が行われると動作は未定義です。
メンバー・オブジェクト#
handle クラス#
メンバー関数
- handle();#
効果: 値を参照しない
handleオブジェクトを構築します。
- handle(handle &&other);#
効果:
concurrent_lru_cacheに格納されている値への参照を、otherから新しく構築されたオブジェクトに転送します。完了すると、otherはどの値も参照しなくなります。
- ~handle();
効果:
concurrent_lru_cacheに格納されている値への参照 (存在する場合) を解放します。
*This を使用した並行操作が行われると動作は未定義です。
- handle &operator=(handle &&other);#
効果:
concurrent_lru_cacheに格納されている値への参照を、otherから*thisに転送します。存在する場合、*thisによって保持された以前の参照が解放されます。完了するとotherはどの値も参照しなくなります。戻り値:
*thisへの参照。
- operator bool() const;#
戻り値:
*thisが値への参照を保持している場合はtrue、それ以外の場合はfalse。
- value_type &value();#
戻り値:
concurrent_lru_cacheに格納されているvalue_typeオブジェクトへの参照。
*this がどの値も参照しない場合、動作は未定義になります。