これstd::set
で、ファイルからを作成する次の簡単なプログラムができました。
#include <fstream>
#include <string>
#include <set>
int main()
{
std::set<std::string> Sdictionnary;
std::set<std::string>::const_iterator it = Sdictionnary.begin();
std::ifstream file("french.txt"); // A file containing 200 000 lines
std::string line;
while(getline(file,line))
{
it = Sdictionnary.insert(it, line);
}
file.close();
return 0;
}
このプログラムを Visual Express の外部で起動すると、約 0.5 秒で起動して終了します。
デバッガーを使用して Visual Express 内でこのプログラムをデバッグ モードまたはリリース モードで起動すると、20 ~ 25 秒後に終了します。ブレークポイントを設定すると、0 が返されます。終了する直前に 25 秒を取得します。25 秒間プログラムを一時停止すると、Visual Express は xmemory に移動します。
void deallocate(pointer _Ptr, size_type)
{ // deallocate object at _Ptr, ignore size
::operator delete(_Ptr);
}
これも で起こっていstd::map
ます。しかし、std::unordered_set
またはではありませんstd::vector
。問題は、Visual Express が特定の種類の連想コンテナー (ソートされたもの ??) でメモリの割り当てを解除するのに、なぜそんなに時間がかかるのかということです。