[Newbies] Binary file I/O performance problems
dfinlayson at usgs.gov
Wed Sep 3 06:00:54 UTC 2008
OK - I made some of the suggested changes. I broke the readers into two parts:
"returns the next unsigned, 32-bit integer from the binary
ifTrue: [^ self nextBigEndianNumber: 4]
ifFalse: [^ self nextLittleEndianNumber: 4]
Where nextLittleEndianNumber looks like this:
"Answer the next n bytes as a positive Integer or
LargePositiveInteger, where the bytes are ordered from least
significant to most significant.
Copied from PositionableStream"
| bytes s |
[bytes := stream next: n.
s := 0.
do: [:i | s := (s bitShift: 8)
bitOr: (bytes at: i)].
do: [^ nil]
This (I think) cleans up some of the code smell, but for only marginal
performance improvements. It seems that I may need to implement a
buffer on the binary stream. Is there a good example on how this
should be done in the image or elsewhere?
I find it troubling that I am having to write code below the
abstraction level of C to read and write data from a file. I thought
Smalltalk was supposed to free me from this kind of drudgery? Right
now, Java looks good and Python/Ruby look fantastic by comparison.
More information about the Beginners