Problems with SmartRefStream

Ned Konz ned at squeakland.org
Sun Nov 7 17:00:22 UTC 2004


On Saturday 06 November 2004 2:12 pm, Albert Sacks wrote:
> output
>         "comment stating purpose of message"
>
>         | strem |
>         strem _ SmartRefStream fileNamed: 'MyModel.obj'.
>         strem nextPut: Foo.
>         strem nextPut: Bar.
>         strem close! !

The problem with this is that you get a file-out header.

You can see this if you do:

f := StandardFileStream fileNamed: 'MyModel.obj'.
f fileInObjectAndCode.

You will get your first Dictionary.

This paragraph in the class comment is important:

---
SmartRefStream works best with only one tree of objects per file.  You can 
nextPut: more than once, but each object tree gets its own class structure 
description, which is big.
---

In actuality, I don't think you can successfully read more than one top-level 
object from a SmartRefStream.

So what one would ordinarily do is to make Test able to stream itself. Which 
it actually is with no extra code. Here's a complete working example:

Test (instVars foo, bar)

 output
  | stream |
  stream := SmartRefStream fileNamed: 'MyModel.obj'.
  stream nextPut: self.

 initialize
  foo := Dictionary new.
  bar := Dictionary new.
  foo at: #Bob put: #Jones.
  foo at: #O put: bar.
  bar at: #Bob put: #Smith.
  bar at: #O put: foo.

Test class

 input
  | stream |
  stream := StandardFileStream fileNamed: 'MyModel.obj'.
  ^stream fileInObjectAndCode.

 example
  | myTest |
  myTest := self new.
  myTest output.
  self input inspect.

-- 
Ned Konz
http://bike-nomad.com/squeak/



More information about the Squeak-dev mailing list