Problems when loading information from a file
<p>I have a doubt. I am writing a code to load information from a file to the computer memory. But the time needed for that is very different depending on the file 'format'.</p>

<p>Let me explain better. In the file that I am reading I have a kind of table with random strings separated with "|". Here you have an example of table (with 5 rows and 5 columns).</p>

<p><em><strong>Table.txt</em></strong></p>

<pre><code>0|42sKuG^uM|24465\lHXP|2996fQo\kN|293cvByiV
1|14772cjZ`SN|28704HxDYjzC|6869xXj\nIe|27530EymcTU
2|9041ByZM]I|24371fZKbNk|24085cLKeIW|16945TuuU\Nc
3|16542M[Uz\|13978qMdbyF|6271ait^h|13291_rBZS
4|4032aFqa|13967r^\\`T|27754k]dOTdh|24947]v_uzg
</code></pre>

<p>And the doubt that I have is that the time spent to load this information is very different if the table has, for example, 100.000 rows and 100 columns or if it has 100 rows and 100.000 columns (in this last case, the time is much higher). Actually the time spent to access to this information is also bigger than in the other cases.</p>

<p>So the doubt is, <strong>Why this time is so different if the table size is the same???</strong></p>

<p>Here you have the part of the code that read this information from a file and store in the computer.</p>

<p><em><strong>Code that reads data from the Table.txt file and store it in the computer memory</em></strong></p>

<pre><code>string ruta_base("C:\\a\\Table.txt"); // Folder where my "Table.txt" is found

string temp; // Variable where every row from the Table.txt file will be firstly stored
vector&lt;string&gt; buffer; // Variable where every different row will be stored after separating the different elements by tokens.
vector&lt;ElementSet&gt; RowsCols; // Variable with a class that I have created, that simulated a vector and every vector element is a row of my table (vector&lt;string&gt; buffer)

ifstream ifs(ruta_base.c_str());

while(getline( ifs, temp )) // We will read and store line per line until the end of the ".txt" file. 
{
    size_t tokenPosition = temp.find("|"); // When we find the simbol "|" we will identify different element. So we separate the string temp into tokens that will be stored in vector&lt;string&gt; buffer

    while (tokenPosition != string::npos)
    {    
        string element;
        tokenPosition = temp.find("|");      

        element = temp.substr(0, tokenPosition);
        buffer.push_back(element);
        temp.erase(0, tokenPosition+1);
    }

    ElementSet ss(0,buffer); 
    buffer.clear();
    RowsCols.push_back(ss); // We store all the elements of every row (stores as vector&lt;string&gt; buffer) in a different position in "RowsCols" 
}

vector&lt;Table&gt; TablesDescriptor;

Table TablesStorage(RowsCols);
TablesDescriptor.push_back(TablesStorage);

DataBase database(1, TablesDescriptor);
</code></pre>

<p>Here I add the <strong>SOLUTION</strong> that I have done with all your feedbacks</p>

<pre><code>string ruta_base("C:\\a\\Table.txt"); // Folder where my "Table.txt" is found

string temp; // Variable where every row from the Table.txt file will be firstly stored
vector&lt;string&gt; buffer; // Variable where every different row will be stored after separating the different elements by tokens.
vector&lt;ElementSet&gt; RowsCols; // Variable with a class that I have created, that simulated a vector and every vector element is a row of my table

ifstream ifs(ruta_base.c_str());

while(getline( ifs, temp )) // We will read and store line per line until the end of the ".txt" file. 
{
       size_t tokenPosition = temp.find("|"); // When we find the simbol "|" we will identify different element. So we separate the string temp into tokens that will be stored in vector&lt;string&gt; buffer

       const char* p = temp.c_str();
      char* p1 = strdup(p);

       char* pch = strtok(p1, "|");
    while(pch)
        {
            buffer.push_back(string(pch));
            pch = strtok(NULL,"|");
        }
        free(p1);

        ElementSet sss(0,buffer);
        buffer.clear();
        RowsCols.push_back(sss);
}

vector&lt;Table&gt; TablesDescriptor;

Table TablesStorage(RowsCols);
TablesDescriptor.push_back(TablesStorage);

DataBase database(1, TablesDescriptor);
</code></pre>
