[erlang-questions] binary typed schema-less protocol

Richard A. O'Keefe ok@REDACTED
Mon Jul 29 03:15:14 CEST 2013

On 29/07/2013, at 1:10 PM, Richard A. O'Keefe wrote:
>    printTNetStringOn: aStream
>      |s|
>      s := StringBuffer new: self size * 6.
>      self do: [:each | each printTNetStringOn: s].
>      s size printOn: aStream.
>      aStream nextPut: $:; nextPutAll: s; nextPut: $].
> 	OUCH!  You have to convert every element to a string,
> 	concatenate them, then write the size of the *string*
> 	(not the *array*), and then the string.  The whole
> 	thing has to be held in memory as a string.  You cannot
> 	stream this.

I should have mentioned that Erlang can do this quite handily using
iolists.  The amount of memory allocated for holding all these
intermediate strings is linear in the size of the result.  That's
in marked contrast to using Java, C++, C#, or Javascript strings.
So TNetStrings almost make sense from an Erlang point of view.  And
Erlang's treatment of binaries makes chopping them up relatively
efficient too.  Even so, "linear space overhead" is still worse than
"zero space overhead".

More information about the erlang-questions mailing list