<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta content="text/html;charset=UTF-8" http-equiv="Content-Type"></head><body ><div style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt;"><div>You guys are awesome.<br></div><div><br></div><div><br></div><div>What I am working towards is that information and examples like this are available as CustomHelp in image for easy access AND aviailable in various markups for easy reading.<br></div><div><br></div><div>This email thread is  a keeper.<br></div><div><br></div><div>thx</div><div><br></div><div><br></div><br><div style="border-top: 1px solid rgb(204, 204, 204); height: 0px; margin-top: 10px; margin-bottom: 10px; line-height: 0px;" class="zmail_extra_hr"><br></div><div style="" data-zbluepencil-ignore="true" class="zmail_extra"><br><div id="Zm-_Id_-Sgn1">---- On Fri, 03 Sep 2021 17:38:40 -0400 <b>Levente Uzonyi <leves@caesar.elte.hu></b> wrote ----<br></div><br><blockquote style="margin: 0px;"><div>Hi Chris, <br> <br>On Fri, 3 Sep 2021, Chris Muller wrote: <br> <br>> Hi Levente, <br>> <br>>       An easy way to avoid that would be to write directly into the file stream, <br>>       but Squeak's file streams are not write-buffered <br>> <br>> <br>> Hm, I always thought they were.  A quick script I used to verify: <br>> <br>> | ws rs | <br>> nil assert: (FileDirectory default fileExists: 'writebuffered') not. <br>> FileDirectory default deleteFileNamed: 'writebuffered'. <br>> [ws := FileStream fileNamed: 'writebuffered'. <br>> rs := FileStream readOnlyFileNamed: 'writebuffered'. <br>> ws nextPutAll: '12345678901'. <br>> "Assert only buffered, not written" <br>>    nil assert: (rs next: 10) isEmpty. <br>> "Force physical write" <br>>    ws flush. <br>> "Assert written" <br>>    nil assert: (rs next: 10) = '1234567890' ] ensure: <br>> [ ws ifNotNil: [ws close]. <br>> rs ifNotNil: [rs close] ] <br> <br>What I meant was actual write buffering at the image level. <br>Without that, each write operation (e.g. #nextPut:) will invoke a <br>primitive to write the contents to the file. <br>Here's an example which also demonstrates the effect of read buffering as <br>a reference: <br> <br>| filename n | <br>filename := UUID new asString36. <br>n := 1000000. <br>[ { <br>     StandardFileStream newFileNamed: filename do: [ :file | <br>         [ n timesRepeat: [ file nextPut: $x ] ] timeToRun ]. <br>     StandardFileStream forceNewFileNamed: filename do: [ :file | <br>         [ n timesRepeat: [ file nextPutAll: 'x' ] ] timeToRun ]. <br>     StandardFileStream forceNewFileNamed: filename do: [ :file | <br>         [ file nextPutAll: (String new: n streamContents: [ :s | <br>             n timesRepeat: [ s nextPut: $x ] ]) ] timeToRun ]. <br>     StandardFileStream forceNewFileNamed: filename do: [ :file | <br>         [ file nextPutAll: (String new: n withAll: $x) ] timeToRun ]. <br>     StandardFileStream readOnlyFileNamed: filename do: [ :file | <br>         [ n timesRepeat: [ file next ] ] timeToRun ]. <br>     StandardFileStream readOnlyFileNamed: filename do: [ :file | <br>         file disableReadBuffering. <br>         [ n timesRepeat: [ file next ] ] timeToRun ]. <br>     StandardFileStream readOnlyFileNamed: filename do: [ :file | <br>         [ file next: n ] timeToRun ].} ] <br>     ensure: [ FileDirectory default deleteFileNamed: filename ] <br>"==> #(137 116 16 1 20 135 1)" <br> <br>The first two blocks write directly to the file, one character a time with <br>#nextPut: and #nextPutAll:, respectively. <br>The third one writes to an in-memory stream first, one character a time, <br>then writes the whole string in a single operation to the file. <br>The fourth one is the same as the third but creates the string directly <br>without streaming the characters one-by-one. <br>The fifth block reads back the file, one character a time using read <br>buffering which is enabled by default. <br>The sixth block does the same but without read buffering. <br>The seventh block reads the contents of the file in a single read <br>operation. <br> <br> <br>Levente<br></div></blockquote></div><div><br></div></div><br></body></html>