Binary Matching

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Binary Matching

Kent Johnson
Does the following code result in a memory copy.

parse(<<Char:8, Rest/binary>>) ->
        %% Do any parsing required
        parse(Rest);
parse(<<>>) ->
        ok.

Thanks,

Kent



Reply | Threaded
Open this post in threaded view
|

Binary Matching

Raimo Niskanen-3
Kent Johnson wrote:
>
> Does the following code result in a memory copy.
>
> parse(<<Char:8, Rest/binary>>) ->
>         %% Do any parsing required
>         parse(Rest);
> parse(<<>>) ->
>         ok.
>

No, not really. For every recursion one new sub-binary will be created
and one will become garbage. The sub-binary is a header of a few words
that shares contents with the original binary to parse.

/ Raimo Niskanen, Erlang/OTP, Ericsson UAB.