Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The TFileStream itself doesn't perform the buffering, that is handled by the OS and is generally sufficient for most purposes. </p> <p>My suggestion would be to build a method to write your data to a stream, and then pass a TSTream parameter to this method. This way you can test different options easily, without impacting your program.</p> <p>For example:</p> <pre><code>Procedure TForm1.StreamMyObjects(aStream : tStream); begin aStream.Write( MyString[1], Length( MyString ) * SizeOf( Char )); aStream.Write( CRLF, Length( CRLF ) * SizeOf( Char )); aStream.Write( MyOtherString[1], Length( MyOtherString ) * SizeOf( Char )); aStream.Write( CRLF, Length( CRLF ) * SizeOf( Char )); end; </code></pre> <p>In the JCL, as before mentioned, there is a TJclBufferedStream which you can then test against to see if there is any performance benefit, which will vary based on what your writing, and how much your writing. For example the following will test a TFileStream, and a tJCLBufferedStream to see what the differences are (yes I know I'm missing the TRY/FINALLY):</p> <pre><code>var fstm : tFileSTream; fBufStm : tJCLBufferedStream; iTicks : Cardinal; fModes : word; // for SO formatting. begin fModes := fmOpenReadWrite or fmCreate or fmShareExclusive; iTicks := GetTickCount; fstm := tFilestream.create('test1.txt',fModes); StreamMyObjects( fStm ); fstm.free; ShowMessage('TEST1='+IntToSTr(GetTickCount-iTicks)); iTicks := GetTickCount; fstm := tFilestream.create('test2.txt',fModes); fBufStm := tJclBufferedStream.create( fStm ); StreamMyObjects( fBufStm ); fBufStm.free; fstm.free; ShowMessage('TEST2='+IntToSTr(GetTickCount-iTicks)); end; </code></pre> <p>in my test, the following routine:</p> <pre><code>procedure TForm1.StreamMyObjects(aSTream: tStream); var St : string; ix : integer; begin for ix := 0 to 10000 do begin St := 'This is a string which is written to a stream. ' + IntToStr(ix); aStream.Write(st[1], Length(st) * SizeOf(Char) ); end; end; </code></pre> <p>returned 47 for the tFilestream, and 16 for the tJCLBufferedStream. Without the loop, the time is insignificant, which is why you need to test against your data...and how much your writing.</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