In-memory stream performance on word data

Yoshiki Ohshima Yoshiki.Ohshima at acm.org
Sat Aug 23 07:28:16 UTC 2003


  Josh,

  I don't fully understand the problem you describe, since I don't
find an image with RWBinaryOrTextStream>>nextPutAll:.  Are you looking
for something that does the opposite operation of
PositionableStream>>nextWordsInto:?

  One way to do this would be:

	words _ B3DRotationArray new: 2.
	words at: 1 put: (B3DRotation radiansAngle: 1.57 axis: (B3DVector3 x: 1.0 y: 2.0 z: 3.0)). "or whatever."

	bytes _ ByteArray new: words basicSize * 4.  "basicSize returns the size in 4 bytes unit."
	hack _ Form new hackBits: bytes.
	eightForm _ Form extent: 4@(bytes size // 4) depth: 8 bits: words.
	Smalltalk isLittleEndian ifTrue:[hack swapEndianness].
	eightForm displayOn: hack.
	"bytes holds the serialized data."

Then, a la Bitmap>>copyFromByteArray:, 

	newWords _ B3DRotationArray new: 2.
	myHack := Form new hackBits: newWords.
	byteHack := Form new hackBits: bytes.
	Smalltalk isLittleEndian ifTrue:[byteHack swapEndianness].
	byteHack displayOn: myHack.

   	newWords = words.
	"=> true"

  I'm not sure this makes it faster (probably does), but may be worth
to try.

  The hackBits thing is picky about the four byte boundary, so I kind
of imagine that do this directly into a byte array of the 'collection'
of a Stream.

-- Yoshiki



More information about the Squeak-dev mailing list