0
std::string line;

This throws std::runtime_error what(): Memory exhausted:

regex_it =  boost::sregex_iterator(line.begin(), line.end(), re);

This works fine:

regex_it = boost::make_regex_iterator(line, re);

Does anyone know what is causing the difference in performance? The boost::regex lib is compiled on Linux in default non-recursive mode.

EDIT: Also tried

regex_it = boost::cregex_iterator(line.data(), line.data()+line.size(), re);

same problem.

2
  • What type is line, and how big is it? Commented Jun 14, 2011 at 22:11
  • added std::string declaration Commented Jun 15, 2011 at 0:39

1 Answer 1

2

Try working with a regex_iterator<char const*> rather than a regex_iterator<std::string::const_iterator>. (Also, the way you're calling make_regex_iterator is unnecessarily verbose by a large measure.)

Assuming line is a std::string, try this:

regex_it = boost::make_regex_iterator(line.c_str(), re);

or this:

regex_it = boost::cregex_iterator(line.data(), line.data() + line.size(), re);
Sign up to request clarification or add additional context in comments.

4 Comments

+1 unnecessarily verbose by a large measure -- what a nice way to put it
I guess I was a bit confused on template function use =P, thanks for that. That essentially solved my issue in a different way since it was the verbosity that was bugging me. However the cregex approach does not work, still getting the out of memory error.
I realized I oversimplified the issue which left out the detail which was causing the problem. The line.begin() and line.end() was actually line.substr(0,pos).begin() and line.substr(0,pos).end(). Since the substring calls make temporary variables, that is copies of the substring, the begin and end iterators don't refer to the same container. I'm going to award this answer since it was the only one.
@Marty : It's not considered bad form to answer your own question. :-]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.