std::string を stxxl::map のキーとして使用しようとしています。10 ~ 100 程度の少数の文字列の場合、挿入は問題ありませんでした。しかし、そこに約100000の多数の文字列を挿入しようとすると、セグメンテーション違反が発生します。
コードは次のとおりです。
struct CompareGreaterString {
bool operator () (const std::string& a, const std::string& b) const {
return a > b;
}
static std::string max_value() {
return "";
}
};
// template parameter <KeyType, DataType, CompareType, RawNodeSize, RawLeafSize, PDAllocStrategy (optional)>
typedef stxxl::map<std::string, unsigned int, CompareGreaterString, DATA_NODE_BLOCK_SIZE, DATA_LEAF_BLOCK_SIZE> name_map;
name_map strMap((name_map::node_block_type::raw_size)*3, (name_map::leaf_block_type::raw_size)*3);
for (unsigned int i = 0; i < 1000000; i++) { /// Inserting 1 million strings
std::stringstream strStream;
strStream << (i);
Console::println("Inserting: " + strStream.str());
strMap[strStream.str()]=i;
}
ここでは、より多くの文字列を挿入できない理由を特定できません。「1377」を挿入すると、正確にセグメンテーション違反が発生します。さらに、任意の数の整数をキーとして追加できます。文字列の可変サイズがこの問題を引き起こしているのではないかと思います。
また、文字列の何を返すのか理解できませんmax_value
。単純に空の文字列を返しました。