Writing a large Collection of integers to a file fast
bert at freudenbergs.de
Sat Jan 26 18:42:51 UTC 2008
On Jan 26, 2008, at 18:44 , Ramon Leon wrote:
>> 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:
The original post asked for printed numbers, not binary 32 bit big-
> 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.
> newFileNamed: 'f.out'
> do:[:f | f nextPutAll: memory asByteArray]
> Why is everyone ignoring that every file open method has a
> #do: that encapsulates the close and removes the need for a temp?
Because that's a rather new addition (since 3.9 maybe?) that won't
work in many images.
- Bert -
More information about the Squeak-dev