System::Collections::Concurrent::ConcurrentDictionary クラス
ConcurrentDictionary class
スレッドセーフな辞書実装です。このクラスのオブジェクトは System::MakeObject() 関数を使用してのみ割り当てるべきです。スタック上や operator new を使ってインスタンスを作成しないでください。そうしないと実行時エラーやアサーション違反が発生します。このクラスは常に System::SmartPtr ポインタでラップし、そのポインタを関数の引数として渡す際に使用してください。
template<class TKey,class TValue>class ConcurrentDictionary : public System::Collections::Generic::Dictionary<TKey, TValue>
| パラメーター | 説明 |
|---|
| TKey | キーの種類です。 |
| TValue | 値型です。 |
メソッド
| メソッド | 説明 |
|---|
| Add(const TKey&, const TValue&) override | 辞書に値を追加します。 |
| Clear() override | コンテナ内のすべての要素を削除します。 |
| CopyTo(ArrayPtr<System::Collections::Generic::KeyValuePair<TKey, TValue>>, int) override | コンテナの要素を既存の配列要素にコピーします。 |
| get_KeysInternal() const override | 辞書のキーにアクセスするためのラッパーコレクションを取得します。 |
| idx_set(const TKey&, TValue) override | RTTI 情報。 |
| Remove(const TKey&) override | コンテナから要素を削除します。 |
| TryAdd(const TKey&, const TValue&) | 辞書にキーと値のペアを追加しようとします。 |
Typedefs
備考
#include <system/collections/concurrent/concurrent_dictionary.h>
#include <system/smart_ptr.h>
using namespace System;
using namespace System::Collections::Generic;
int main()
{
const int itemsCount = 32;
// ConcurrentDictionary クラスのインスタンスを作成します。
auto concurrentDictionary = MakeObject<ConcurrentDictionary<int, int>>();
// ConcurrentDictionary にデータを追加します。
for (auto i = 0; i < itemsCount; ++i)
{
concurrentDictionary->Add(i, i * i);
}
Console::WriteLine(concurrentDictionary->idx_get(3));
return 0;
}
/*
This code example produces the following output:
9
*/
参照