Writing a large Collection of integers to a file fast
Ramon Leon
ramon.leon at allresnet.com
Sat Jan 26 17:44:13 UTC 2008
> If you have only small integers and free memory, the fastest
> method (just one i/o) would be
>
> | memory fOut |
> memory := Bitmap new: 6 * 1000 * 1000.
> memory atAllPut: SmallInteger maxVal.
> [(fOut := StandardFileStream newFileNamed: 'f.out')
> nextPutAll: memory asByteArray]
> ensure: [fOut close]
>
> You can fill the memory instance with #integerAt:put:
>
> /Klaus
On a side note, watching this thread, I'm a bit curious why everyone is
manually closing their files, why not...
| memory |
memory := Bitmap new: 6 * 1000 * 1000.
memory atAllPut: SmallInteger maxVal.
FileStream
newFileNamed: 'f.out'
do:[:f | f nextPutAll: memory asByteArray]
Why is everyone ignoring that every file open method has a corresponding
#do: that encapsulates the close and removes the need for a temp?
Ramon Leon
http://onsmalltalk.com
More information about the Squeak-dev
mailing list
|