Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When made my comment to your question, I didn't have the time to elaborate, so here's an attempt to answer. The code has changed since, and I'm not sure I would add that comment to the code as it is now. </p> <p>Nevertheless, the underlying reason that made me add that comment still stands: <strong><em>Unless you measured</em></strong> and found that the code in question does indeed have a significant negative impact on performance, <strong><em>don't attempt to optimize</em></strong>. Instead, strive to make your code <strong><em>as readable as possible</em></strong>. </p> <p>I seriously doubt that copying the data in memory will have a significant performance impact after copying them from the disk into memory. However, since your code as provided makes assumptions about the struct's layout in memory anyway, directly reading into the struct wouldn't really make the code less readable (or less vulnerable to changes to that layout): </p> <pre><code>COUPLE titanic; FILE *f = fopen("myfile", "rb"); fread(&amp;titanic, sizeof(titanic), 1, f); </code></pre> <p>Or, if you indeed have an array, read into the array directly: </p> <pre><code>COUPLE titanic[SIZE]; FILE *f = fopen("myfile", "rb"); fread(&amp;titanic, sizeof(titanic), SIZE, f); </code></pre> <p>Depending on <code>SIZE</code>, the latter could indeed make a potentially huge difference in performance. Accessing the disk for bigger chunks is, in general, faster that doing it for smaller chunks. (Although disk caching might alleviate that.) </p>
 

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