title: Most memory-efficient way to read & store list of strings in C
body: <p>I'd like to know what's the most memory efficient way to read &amp; store a list of strings in C.</p>
  
  <p>Each string may have a different length, so pre-allocating a big 2D array would be wasteful.
  I also want to avoid a separate malloc for each string, as there may be many strings.</p>
  
  <p>The strings will be read from a large buffer into this list data-structure I'm asking about.</p>
  
  <p>Is it possible to store all strings separately with a single allocation of exactly the right size?</p>
  
  <p>One idea I have is to store them contiguously in a buffer, then have a char * array pointing to the different parts in the buffer, which will have '\0's in it to delimit. I'm hoping there's a better way though.</p>
  
  <pre><code>struct list {
    char *index[32];
    char buf[];
  };
  </code></pre>
  
  <p>The data-structure and strings will be strictly read-only.</p>