String representation in erlang

Richard Cameron camster@REDACTED
Thu Sep 15 12:12:09 CEST 2005


On 13 Sep 2005, at 15:17, Joe Armstrong (AL/EAB) wrote:

> 2> size(term_to_binary(packer:packstring(S))).
> 42
> 3> size(term_to_binary(S)).
> 30
>
> [snip]
>
> You might need to compresses them on disk to save space but then  
> you need
> real compression, like LZSS...

... and you get compression for free if you use term_to_binary/2:

1> size(term_to_binary(lists:duplicate(1000000,$A))).
2000007
2> size(term_to_binary(lists:duplicate(1000000,$A), [compressed])).
1977

I use it to transport large chunks of data between distributed nodes  
over a (slow) network, and it works beautifully. At the other end,  
binary_to_term will automatically recognise the data as being in a  
compressed format and just do the right thing.

Richard.



More information about the erlang-questions mailing list