working with binaries
Tue Jul 11 15:23:01 CEST 2006
Christian S wrote:
> list_to_binary([A,B]) for concatenation.
> As for sub binaries, I tend to use pattern matching.
> 1> A = <<"ABCDEFGHIJKLM">>.
> 2> <<_:5/binary,Sub:3/binary,_/binary>> = A.
> 3> Sub.
> It would be interesting to hear comments on the pattern matching
> approach. I tend to use the method to index individual bytes from
> binaries too. Is it terribly inefficient or as low constant factor
> O(1) as one can get?
Indexing an individual byte in a binary using pattern matching is
reasonably efficient. It is O(1) and pretty close to using a bif to
index the binary, in fact if you extract several values in one pattern
matching statement it is often faster than using a bif to extract the
More information about the erlang-questions