Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>At least if I'm reading this correctly, I think I'd take a rather more C-like approach. Instead of reading a line, then breaking it up into tokens, and stripping out the characters you don't want, I'd read a character at a time, and based on the character I read, decide whether to add it to the current token, end the token and add it to the current line, or end the line and add it to the vector of lines:</p> <pre><code>#include &lt;vector&gt; #include &lt;string&gt; #include &lt;stdio.h&gt; #include &lt;time.h&gt; std::vector&lt;std::vector&lt;std::string&gt; &gt; read_tokens(char const *filename) { std::vector&lt;std::vector&lt;std::string&gt; &gt; lines; FILE *infile= fopen(filename, "r"); int ch; std::vector&lt;std::string&gt; line; std::string token; while (EOF != (ch = getc(infile))) { switch(ch) { case '\n': lines.push_back(line); line.clear(); token.clear(); break; case '"': break; case '*': line.push_back(token); token.clear(); break; default: token.push_back(ch); } } return lines; } int main() { clock_t start = clock(); std::vector&lt;std::vector&lt;std::string&gt; &gt; lines = read_tokens("sample_tokens.txt"); clock_t finish = clock(); printf("%f seconds\n", double(finish-start)/CLOCKS_PER_SEC); return 0; } </code></pre> <p>Doing a quick test with this on a file with a little over 200K copies of the sample you gave in the comment, it's reading and (apparently) tokenizing the data in ~3.5 second with gcc or ~4.5 seconds with VC++. I'd be a little surprised to see anything get a whole lot faster (at least without faster hardware).</p> <p>As an aside, this is handling memory about as you originally did, which (at least in my opinion) is pretty strong evidence that managing memory in the vector probably isn't a major bottleneck.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload