[Newbies] Binary file I/O performance problems

David Finlayson 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:

uint32
	"returns the next unsigned, 32-bit integer from the binary
	stream"
	isBigEndian
		ifTrue: [^ self nextBigEndianNumber: 4]
		ifFalse: [^ self nextLittleEndianNumber: 4]

Where nextLittleEndianNumber looks like this:

nextLittleEndianNumber: n
	"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.
	n
		to: 1
		by: -1
		do: [:i | s := (s bitShift: 8)
						bitOr: (bytes at: i)].
	^ s]
		on: Error
		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.

David


More information about the Beginners mailing list