[erlang-questions] map over bitstring

Morten Krogh mk@REDACTED
Fri Oct 22 14:56:32 CEST 2010

Hi Jesper

On 10/22/10 2:26 PM, Jesper Louis Andersen wrote:
> On Fri, Oct 22, 2010 at 1:15 PM, Morten Krogh<mk@REDACTED>  wrote:
>> Hi Jesper
>> Thanks for the link!
>> It seems to me that the requirement that binaries must be contiguous in
>> memory is quite strict.
>> If that requirement was abandoned, binaries could be lists of ProcBins, or
>> whatever they are called, instead.
> This is essentially iolists you are proposing. They are already in the
> language, see
> http://prog21.dadgum.com/70.html
> for a quick discussion of them.

Yes, but my suggestion would let the VM handle lists of binaries instead 
of the application programmer.
My lists only contain binaries. They are not full iolists, which I guess 
they could be.

>> Simple example from my module zip2
> [...]
>> Why is the memory usage 300 MB. It should have been 100MB, and in worst
>> case, with naive copying, 200MB.
>> But 300 MB.
> My guess is that B has some excess space allocated for appending which
> amount to around 100Mb (you should probably not go with a 100Mb binary
> in the first place, but rather an iolist of smaller binaries). B's
> extra space will only get shrunk away when the runtime decide to
> transfer the binary to another process and it is not before it is sent
> back to the shell as a message.
> My guess might be wrong though.
It is actually 200 MB extra.

Transfering the binaries to the shell, removes 100 MB, so you were 
right. But 200 MB in total is still allocated.

It is still not clear to me. At B = <<A/binary, 97>>, 200 MB is 
allocated behind A? Or somewhere else?
And after message passing, 200 MB of extra space is shrunk to 100MB 
beyond the 100MB of actual data?


More information about the erlang-questions mailing list