OrderedCollection>>writeStream

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

OrderedCollection>>writeStream

Chris Uppal-3
I think this is a bug:

    (OrderedCollection writeStream) nextPutAll: 'help'.

gives a walkback.  It dates back to 2.1 at least.

I came across it in a context like:

o := OrderedCollection withAll: 'hello'.
s := o readStream.
... later, in another method ...
c := s upTo: $l.

BTW: Isn't Collection>>growSize the wrong way around ?  I'd have expected it
to answer the *minimum* of the current size and 2.  (The collections
underlying WriteStreams don't actually seem to be growing in steps of 2,
presumably because it's the VM primitive that gets called in practise).

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: OrderedCollection>>writeStream

Blair McGlashan
Chris

You wrote in message
news:[hidden email]...
> I think this is a bug:
>
>     (OrderedCollection writeStream) nextPutAll: 'help'.
>
> gives a walkback.  It dates back to 2.1 at least.

I agree with you, but Smalltalk-80 has historically not supported streaming
into an OrderedCollection. You'll get a similar error in Squeak, and I think
older versions of VW as well. I am intending to fix it though, as it seems a
bit silly, hence it exists as defect 221 (having come up recently).

> ...snip...
> BTW: Isn't Collection>>growSize the wrong way around ?  I'd have expected
it
> to answer the *minimum* of the current size and 2.  (The collections
> underlying WriteStreams don't actually seem to be growing in steps of 2,
> presumably because it's the VM primitive that gets called in practise).

No the idea is to double the size of the collection when it needs to grow,
but to add at least two elements in case it is empty, therefore it wants to
answer the larger of the current size and 2, hence #max. If it were the
other way around then the collections really would grow only in increments
of 2 (the #resize: primitive does what it is told and resizes the object to
the size requested), which would lead to rather dismal performance!

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: OrderedCollection>>writeStream

Chris Uppal-3
Blair,

> >     (OrderedCollection writeStream) nextPutAll: 'help'.
> >
> > gives a walkback.  It dates back to 2.1 at least.
>
> I agree with you, but Smalltalk-80 has historically not supported
streaming
> into an OrderedCollection. You'll get a similar error in Squeak, and I
think
> older versions of VW as well. I am intending to fix it though, as it seems
a
> bit silly, hence it exists as defect 221 (having come up recently).

Were you (or whoever) trying to port Paul Baumann's "State Relication
Protocol" by any chance?  That's where I found it.


> > ...snip...
> > BTW: Isn't Collection>>growSize the wrong way around ?  I'd have
expected
> it
> > to answer the *minimum* of the current size and 2.  (The collections
> > underlying WriteStreams don't actually seem to be growing in steps of 2,
> > presumably because it's the VM primitive that gets called in practise).
>
> No the idea is to double the size of the collection when it needs to grow,

Yes, of course.  My brain must have been more than normally loose in its
socket on Friday.  Sorry about that.

> Blair

    -- chris