Performance reading binary files
<p>I have a program that reads from a really big binary file (48 MB) and then passes the data to a matrix of custom structs named pixel:</p>

<pre><code>struct pixel {
    int r;
    int g;
    int b;
};
</code></pre>

<p>Opening the file:</p>

<pre><code>ifstream myFile(inputPath, ios::binary);
pixel **matrixPixel;
</code></pre>

<p>The read of the file is done this way:</p>

<pre><code>int position = 0;

for (int i = 0; i &lt; HEIGHT; ++i) {
        for (int j = 0; j &lt; WIDTH; ++j) {
            if (!myFile.eof()) {
                myFile.seekg(position, ios::beg);
                myFile.read((char *) &amp;matrixPixel[i][j].r, 1); // red byte
                myFile.seekg(position + HEIGHT * WIDTH, ios::beg);
                myFile.read((char *) &amp;matrixPixel[i][j].g, 1); // green byte
                myFile.seekg(position + HEIGHT * WIDTH * 2, ios::beg);
                myFile.read((char *) &amp;matrixPixel[i][j].b, 1); // blue byte
                ++position;
            }
        }
    }
myFile.close();
</code></pre>

<p>The thing is that, for a big file like the one at the beginning, it takes a lot of time (~7 min) and it's supposed to be optimized. How could I read from the file in less time?</p>