Streaming on OrderedCollection

Travis Griggs tgriggs at keyww.com
Fri Sep 4 04:39:38 UTC 1998



Bob Arning wrote:

> On Thu, 03 Sep 1998 14:50:45 -0700 Travis Griggs <tgriggs at keyww.com> wrote:
>
> >> Do you really want a stream on an OrderedCollection?
> >
> >Yes. I consider OrderedCollection the workhorse of Smalltalk collections. Interesting collection type things are usually done with them. The fact that VW, ST/X, and now as you point out, VSE, supports WriteStream'ing on an OC, would seem to validate this.
> >
>
> Well, I didn't actually say that I remembered VSE supporting WriteStreams on OrderedCollections, just that OrderedCollection did support an #at:put: that was outside the bounds of the current #size. I may even be wrong about that. They say memory is the first thing to go. Or was it something else? I forget.

And it actually sounds like from other contributors to this thread that VW may be nearly unique in this regard, as VA and VSE apparently do not support this. I stand/sit corrected.

> >> There are probably other similar problems lurking here (OrderedCollection>>size, e.g.). In addition you are incurring an extra level of overhead - especially since some methods in Stream classes are actually primitives that work for String and Array collections. Perhaps you'll be happier all around using an Array instead.
> >
> >No, I don't think so. If multiple other Smalltalks can do this, I can't imagine it's that hard. I've never had any sort of weird problems in ST/X or VW because WriteStream'ing worked on both OCs and Arrays. I haven't looked at the methods in the Squeak stream classes, but it sounds like I might be doing more of it. :) If as you say is true, that some of the methods include
> >primitives which are specialized for String/Array, then that's wrong. If such is the case, then a subclass of WriteStream called StringWriteStream, or ArrayWriteStream should be written, which overrideds a more generic implementation with the appropriate primitive.
> >
>
> Two things:
>
> 1. You can have your cake and eat it too by writing
>         stream _ WriteStream with: myOC asArray.
>         ... add stuff to the stream ...
>         myOC _ stream contents asOrderedCollection
>
> 2. The primitives provided merely accelerate commonly used combinations of selector and state. They still work with other combinations, but at normal Smalltalk speeds. For that reason, the above example may provide you with significant performance improvements.

That could be. But then maybe the overhead of creating the intermediate Array would outweigh what one got from the primitive implementations. Moreso than that, what started this was some methods that were already in the system. I wanted to use with:collect: for the Numeric Collections stuff. I wanted this framework to basically work for any sort of OrderedCollection. In the VW
version, we do numeric stuff to OCs ALL of the time (thus my previous comment about OC being the collection workhorse) using said framework. There we had implemented with:collect: in SequenceableCollection as ReadStreams on the two collections and a WriteStream for the new one. Then we overwrote the Array subclass versions of with:collect: to use at: and at:put: sends where
safe. IOW, the current implementation of with:collect: shouldn't be implemented in SequenceableCollection unless it supports all kinds of subclasses, it should be implemented in ArrayedCollection.


> As to the ANSI specs, they do seem to say that you can ask a WriteStream factory to accept an OrderedCollection as its initial contents. The problem is in using the OrderedCollection as the collection behind the stream AND trying to use #at:put: on it since the OC only support #at:put: for currently existing elements. Which, I think, is what you were saying in the beginning.

I'm recanting all over the place tonight. IF I read Allens reply right, this situation (WriteStream'ing on an OrderedCollection) is basically not defined and left up to implementations. So much for portability.

--
Travis Griggs
Key Technology
tgriggs at keyww.com
Smalltalk - 100% Pure Objects, Always had 'em, Always will!





More information about the Squeak-dev mailing list