title: Should I use a TMemoryStream as an efficient buffer before writing to a file?
body: <p>I am using D6 Professional and need to create a text file in a specific format from lots of small strings already in memory. For performance reasons, I am considering using a TMemoryStream to collate the file data, and then write it out to disk in one go via a TFileStream.</p>
  
  <p>But I have a half forgotten memory (probably from pre-D6 days) of reading somewhere that TMemoryStream is inefficient, especially after it hits its Capacity size. My Delphi (and Windows API) skill is not good enough to check the Classes.pas code for myself. </p>
  
  <p>(OFFTOPIC) especially code like this: (line 5152 of Classes.pas):<br>
      NewCapacity := (NewCapacity + (MemoryDelta - 1)) and not (MemoryDelta - 1);<br>
  (/OFFTOPIC)</p>
  
  <p>Adding to my worry is that the conclusion of a related question
      <a href="https://stackoverflow.com/questions/486843/using-memorystream-to-write-out-to-xml">Using MemoryStream to write out to XML</a><br>
  was <B>not</B> to use TMemoryStream, but didn't say why - whether due to TMemoryStream itself, or because there is sufficient buffering in the TFileStream or the I/O device driver, or just the specifics of the code in question.</p>
  
  <p>Thanks for any advice<br>
  Regards,<br>
  PhilW.  </p>