[erlang-questions] Binary matching implementation / performance

Håkan Stenholm hokan.stenholm@REDACTED
Sat Jul 14 02:12:56 CEST 2007


Christopher Baus wrote:
> Hi,
>
> I'm learning erlang, and I have a question regarding binary matching
> performance and implementation.
>
> Consider:
>
> <<X,Rest/binary>> = <<"somebinarydata">>.
>
> Are X and Rest constructed by copying and reallocating the underlying
> buffer (I suspect they are), or do the new variables just contain pointers
> to the original data?
>
>   
They are just pointers, this has been mentioned on the mailing list a 
couple of days ago - erlang.org and trapexit should have a searchable 
archive.

Erlang only copies data when you build a new binary, not when you 
pattern match against a existing binary.

As Erlang memory "objects" are imutable once created - it would 
(generally) make little sense to do a copy of their content.
This is why for example updating a tuple will only create a new array of 
tuple member pointers in the erlang VM, or why doing L = [E | R] will 
only create a "cons box" (pair of pointers) to create L.

> If rest is sufficiently long, reallocating could be very slow and would
> probably require converting the binary to a list.
>
> Thanks,
>
> Chris
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>   




More information about the erlang-questions mailing list