boost tokenize me mange toute ma mémoire vive :(
Bonjour,
J'ai une classe qui notament parse un fichier afin de récupérer les tokens. La compilation marche bien. Mais l'éxécutable me mange toute ma ram et fini par dire:
Citation:
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Abandon (core dumped)
Pourtant le fichier a parser et minuscule (pour l'instant je fais des test)
Citation:
Envoyé par Le fichier
R1,(R2 R3),(R4 R5),(R6 R7),(R8 R9),R16,(R18 R12),(R23 -R11),R10,R13,R14,R15,R17,R19,R20,R21,R22,
La classe posant problème!
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #include "Reaction.hpp"
namespace tools
{
Reaction::Reaction(std::wstring newPath) : path(newPath)
{
// Create flow
std::wifstream file(toANSI(path).c_str(), std::ios::in);
// Current line
std::wstring line;
// typedef for a better readable code
typedef boost::tokenizer< boost::char_separator<wchar_t>, std::wstring::const_iterator, std::wstring > tokenizer;
// The separator
boost::char_separator<wchar_t> separator( L"," );
// If open file success
if (file)
{
while (std::getline(file, line))
{
// While string is not empty
while (!line.empty())
{
// Personal tokeniser
tokenizer tokens( line, separator );
//std::copy( tokens.begin(), tokens.end(), std::back_inserter(reactions) );
for (tokenizer::iterator tokenIterator = tokens.begin(); tokenIterator != tokens.end(); ++tokenIterator)
{
reactions.push_back(*tokenIterator);
}
}
}
file.close();
}
else
{
std::wcerr << "Error! Can not open file: " << path << std::endl;
exit(EXIT_FAILURE);
}
}
Reaction::~Reaction()
{
}
std::wstring Reaction::getPath() const
{
return path;
}
std::vector<std::wstring> Reaction::getReactions() const
{
return reactions;
}
std::wstring Reaction::getReactions(int index) const
{
return reactions.at(index);
}
} |
En plus boost::tokenizer n'est pas multi threadé c'est facheux ça me prend qu'un seul proc en entier! Quel gachis
En vous remerciant de votre aide