[Pharo-project] Basic tricks for improving a serializer?

Sven Van Caekenberghe sven at beta9.be
Tue May 17 22:31:18 CEST 2011

On 17 May 2011, at 21:57, Mariano Martinez Peck wrote:

> Sven, I want to make it work :)
> so....the missing methods I told you that I need are:
> #nextStringPut:     
> #nextNumber:put:
> #nextInt32Put:
> #nextWordPut:

I guess these are pretty easy. But I think they clutter the interface of ZnBufferedWriteStream, so maybe you should make a subclass.

> #contents
> Implement #contents I guess it is something like:
> ZnBufferedWriteStream >> contents
> ^ stream contents

Why to you need #contents ? I would say that it goes a bit against the concept of a stream as a sink of data.
I haven't looked, but I would guess that saying #contents to a FileStream is not efficient.

> Those missing methods I need are implemented PositionableStream. I took the implementation from there and  put it in ZnBufferedWriteStream.
> I just added to them a first line "    self flushBufferIfFull."

That is probably OK, except when your string becomes larger than the buffer. Have a look at #nextPutAll:

> The way I am creating it is like this:
> stream := ZnBufferedWriteStream on: ((FileDirectory default forceNewFileNamed: 'mariano') binary).
> So...is this correct Sven?   My tests are green :)

That seems OK

> Still need to try benchmarks.

You might also consider playing with making the buffer larger.


More information about the Pharo-project mailing list