[erlang-questions] matching binary against a file

Mike McNally m5@REDACTED
Fri Jun 22 14:49:30 CEST 2007


> However, note that building ever-larger binaries in a
> loop may be very expensive. An operation like
> <<S/binary,C>> may mean copying S and C into a new
> binary in each iteration (cost = size(S)+size(C)),
> which turns the algorithm quadratic or worse as the
> accumulated S grows with each iteration.

Is it the case that the runtime creates new binaries (i.e., makes
copies) in a loop that's iterating on fragments of an existing binary?
In other words, if an iteration matches a portion of a binary

   loop_fun(<<_:X, Remainder/binary>>) ->
     %% ...
     loop_fun(Remainder);

Will that have to create a new binary?  I had assumed not, but I know
very little about how the runtime actually works.


--
[ I love pre-moistened towelettes ] Mike McNally -- m5@REDACTED



More information about the erlang-questions mailing list